Index: client/libs/logdog/tests/streamname_test.py |
diff --git a/client/libs/logdog/tests/streamname_test.py b/client/libs/logdog/tests/streamname_test.py |
index c84292a6554a30417868d8ed57089a6afd84c422..321fc7243080dd2d67c910455236134adbc67666 100755 |
--- a/client/libs/logdog/tests/streamname_test.py |
+++ b/client/libs/logdog/tests/streamname_test.py |
@@ -62,5 +62,63 @@ class StreamNameTestCase(unittest.TestCase): |
self.assertRaises(ValueError, streamname.normalize, '_invalid_start_char') |
+class StreamPathTestCase(unittest.TestCase): |
+ |
+ def testParseValidPath(self): |
+ for path in ( |
+ 'foo/+/bar', |
+ 'foo/bar/+/baz', |
+ ): |
+ prefix, name = path.split('/+/') |
+ parsed = streamname.StreamPath.parse(path) |
+ self.assertEqual( |
+ parsed, |
+ streamname.StreamPath(prefix=prefix, name=name)) |
+ self.assertEqual(str(parsed), path) |
+ |
+ def testParseInvalidValidPathRaisesValueError(self): |
+ for path in ( |
+ '', |
+ 'foo/+', |
+ 'foo/+/', |
+ '+/bar', |
+ '/+/bar', |
+ 'foo/bar', |
+ '!!!invalid!!!/+/bar', |
+ 'foo/+/!!!invalid!!!', |
+ ): |
+ with self.assertRaises(ValueError): |
+ streamname.StreamPath.parse(path) |
+ |
+ def testUrlQuote(self): |
+ self.assertEqual( |
+ streamname.StreamPath.make('foo', 'bar/baz').urlquote(), |
+ 'foo%2F%2B%2Fbar%2Fbaz') |
+ |
+ def testLogDogViewerUrl(self): |
+ for path, url in ( |
+ (streamname.StreamPath(prefix='foo', name='bar/baz'), |
+ 'https://example.appspot.com/v/?s=foo%2F%2B%2Fbar%2Fbaz'), |
+ |
+ (streamname.StreamPath(prefix='foo', name='bar/**'), |
+ 'https://example.appspot.com/v/?s=foo%2F%2B%2Fbar%2F%2A%2A'), |
+ |
+ (streamname.StreamPath(prefix='**', name='**'), |
+ 'https://example.appspot.com/v/?s=%2A%2A%2F%2B%2F%2A%2A'), |
+ ): |
+ self.assertEqual( |
+ streamname.get_logdog_viewer_url('example.appspot.com', path), |
+ url) |
+ |
+ # Multiple streams. |
+ self.assertEqual( |
+ streamname.get_logdog_viewer_url('example.appspot.com', |
+ streamname.StreamPath(prefix='foo', name='bar/baz'), |
+ streamname.StreamPath(prefix='qux', name='**'), |
+ ), |
+ ('https://example.appspot.com/v/?s=foo%2F%2B%2Fbar%2Fbaz&' |
+ 's=qux%2F%2B%2F%2A%2A')) |
+ |
+ |
if __name__ == '__main__': |
unittest.main() |