Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: client/libs/logdog/tests/stream_test.py

Issue 2453273002: Update LogDog client library to generate URLs. (Closed)
Patch Set: Forgot project, oops. Addressed nits. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/libs/logdog/tests/bootstrap_test.py ('k') | client/libs/logdog/tests/streamname_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/libs/logdog/tests/stream_test.py
diff --git a/client/libs/logdog/tests/stream_test.py b/client/libs/logdog/tests/stream_test.py
index 98cbbdacb971f7362546eb45df12b4afdefe2f44..008379f8c318fee52d8f1fdb7524c07b43ea1092 100755
--- a/client/libs/logdog/tests/stream_test.py
+++ b/client/libs/logdog/tests/stream_test.py
@@ -14,7 +14,7 @@ ROOT_DIR = os.path.dirname(os.path.abspath(os.path.join(
os.pardir, os.pardir, os.pardir)))
sys.path.insert(0, ROOT_DIR)
-from libs.logdog import stream, varint
+from libs.logdog import stream, streamname, varint
class StreamParamsTestCase(unittest.TestCase):
@@ -93,14 +93,14 @@ class StreamClientTestCase(unittest.TestCase):
return json.loads(header), data.read()
class _TestStreamClient(stream.StreamClient):
- def __init__(self, value):
- super(StreamClientTestCase._TestStreamClient, self).__init__()
+ def __init__(self, value, **kwargs):
+ super(StreamClientTestCase._TestStreamClient, self).__init__(**kwargs)
self.value = value
self.last_conn = None
@classmethod
- def _create(cls, value):
- return cls(value)
+ def _create(cls, value, **kwargs):
+ return cls(value, **kwargs)
def _connect_raw(self):
conn = StreamClientTestCase._TestStreamClientConnection()
@@ -128,8 +128,17 @@ class StreamClientTestCase(unittest.TestCase):
self.assertEqual(client.value, 'value')
def testTextStream(self):
- client = self._registry.create('test:value')
+ client = self._registry.create('test:value',
+ project='test',
+ prefix='foo/bar',
+ coordinator_host='example.appspot.com')
with client.text('mystream') as fd:
+ self.assertEqual(
+ fd.path,
+ streamname.StreamPath(prefix='foo/bar', name='mystream'))
+ self.assertEqual(
+ fd.get_viewer_url(),
+ 'https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fmystream')
fd.write('text\nstream\nlines')
conn = client.last_conn
@@ -144,6 +153,14 @@ class StreamClientTestCase(unittest.TestCase):
with client.text('mystream', content_type='foo/bar',
tee=stream.StreamParams.TEE_STDOUT,
tags={'foo': 'bar', 'baz': 'qux'}) as fd:
+ self.assertEqual(
+ fd.params,
+ stream.StreamParams.make(
+ name='mystream',
+ type=stream.StreamParams.TEXT,
+ content_type='foo/bar',
+ tee=stream.StreamParams.TEE_STDOUT,
+ tags={'foo': 'bar', 'baz': 'qux'}))
fd.write('text!')
conn = client.last_conn
@@ -160,8 +177,17 @@ class StreamClientTestCase(unittest.TestCase):
self.assertEqual(data, 'text!')
def testBinaryStream(self):
- client = self._registry.create('test:value')
+ client = self._registry.create('test:value',
+ project='test',
+ prefix='foo/bar',
+ coordinator_host='example.appspot.com')
with client.binary('mystream') as fd:
+ self.assertEqual(
+ fd.path,
+ streamname.StreamPath(prefix='foo/bar', name='mystream'))
+ self.assertEqual(
+ fd.get_viewer_url(),
+ 'https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fmystream')
fd.write('\x60\x0d\xd0\x65')
conn = client.last_conn
@@ -172,8 +198,17 @@ class StreamClientTestCase(unittest.TestCase):
self.assertEqual(data, '\x60\x0d\xd0\x65')
def testDatagramStream(self):
- client = self._registry.create('test:value')
+ client = self._registry.create('test:value',
+ project='test',
+ prefix='foo/bar',
+ coordinator_host='example.appspot.com')
with client.datagram('mystream') as fd:
+ self.assertEqual(
+ fd.path,
+ streamname.StreamPath(prefix='foo/bar', name='mystream'))
+ self.assertEqual(
+ fd.get_viewer_url(),
+ 'https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fmystream')
fd.send('datagram0')
fd.send('dg1')
fd.send('')
@@ -187,6 +222,35 @@ class StreamClientTestCase(unittest.TestCase):
self.assertEqual(list(self._split_datagrams(data)),
['datagram0', 'dg1', '', 'dg3'])
+ def testStreamWithoutPrefixCannotGenerateUrls(self):
+ client = self._registry.create('test:value',
+ coordinator_host='example.appspot.com')
+ with client.text('mystream') as fd:
+ self.assertRaises(KeyError, fd.get_viewer_url)
+
+ def testStreamWithoutInvalidPrefixCannotGenerateUrls(self):
+ client = self._registry.create('test:value',
+ project='test',
+ prefix='!!! invalid !!!',
+ coordinator_host='example.appspot.com')
+ with client.text('mystream') as fd:
+ self.assertRaises(ValueError, fd.get_viewer_url)
+
+ def testStreamWithoutProjectCannotGenerateUrls(self):
+ client = self._registry.create('test:value',
+ prefix='foo/bar',
+ coordinator_host='example.appspot.com')
+ with client.text('mystream') as fd:
+ self.assertRaises(KeyError, fd.get_viewer_url)
+
+ def testStreamWithoutCoordinatorHostCannotGenerateUrls(self):
+ client = self._registry.create('test:value',
+ project='test',
+ prefix='foo/bar')
+ with client.text('mystream') as fd:
+ self.assertRaises(KeyError, fd.get_viewer_url)
+
+
def testCreatingDuplicateStreamNameRaisesValueError(self):
client = self._registry.create('test:value')
with client.text('mystream') as fd:
« no previous file with comments | « client/libs/logdog/tests/bootstrap_test.py ('k') | client/libs/logdog/tests/streamname_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698