OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The LUCI Authors. All rights reserved. | 2 # Copyright 2016 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 import unittest | 8 import unittest |
9 | 9 |
10 ROOT_DIR = os.path.dirname(os.path.abspath(os.path.join( | 10 ROOT_DIR = os.path.dirname(os.path.abspath(os.path.join( |
11 __file__.decode(sys.getfilesystemencoding()), | 11 __file__.decode(sys.getfilesystemencoding()), |
12 os.pardir, os.pardir, os.pardir))) | 12 os.pardir, os.pardir, os.pardir))) |
13 sys.path.insert(0, ROOT_DIR) | 13 sys.path.insert(0, ROOT_DIR) |
14 | 14 |
15 from libs.logdog import bootstrap | 15 from libs.logdog import bootstrap, stream |
16 | 16 |
17 | 17 |
18 class BootstrapTestCase(unittest.TestCase): | 18 class BootstrapTestCase(unittest.TestCase): |
19 | 19 |
20 def setUp(self): | 20 def setUp(self): |
21 self.env = { | 21 self.env = { |
22 bootstrap.ButlerBootstrap._ENV_PROJECT: 'test-project', | 22 bootstrap.ButlerBootstrap._ENV_PROJECT: 'test-project', |
23 bootstrap.ButlerBootstrap._ENV_PREFIX: 'foo/bar', | 23 bootstrap.ButlerBootstrap._ENV_PREFIX: 'foo/bar', |
24 bootstrap.ButlerBootstrap._ENV_STREAM_SERVER_PATH: 'fake:path', | 24 bootstrap.ButlerBootstrap._ENV_STREAM_SERVER_PATH: 'fake:path', |
| 25 bootstrap.ButlerBootstrap._ENV_COORDINATOR_HOST: 'example.appspot.com', |
25 } | 26 } |
26 | 27 |
27 def testProbeSucceeds(self): | 28 def testProbeSucceeds(self): |
28 bs = bootstrap.ButlerBootstrap.probe(self.env) | 29 bs = bootstrap.ButlerBootstrap.probe(self.env) |
29 self.assertEqual(bs, bootstrap.ButlerBootstrap( | 30 self.assertEqual(bs, bootstrap.ButlerBootstrap( |
30 project='test-project', | 31 project='test-project', |
31 prefix='foo/bar', | 32 prefix='foo/bar', |
32 streamserver_uri='fake:path')) | 33 streamserver_uri='fake:path', |
| 34 coordinator_host='example.appspot.com')) |
33 | 35 |
34 def testProbeNoBootstrapRaisesError(self): | 36 def testProbeNoBootstrapRaisesError(self): |
35 self.assertRaises(bootstrap.NotBootstrappedError, | 37 self.assertRaises(bootstrap.NotBootstrappedError, |
36 bootstrap.ButlerBootstrap.probe, env={}) | 38 bootstrap.ButlerBootstrap.probe, env={}) |
37 | 39 |
38 def testProbeMissingProjectRaisesError(self): | 40 def testProbeMissingProjectRaisesError(self): |
39 self.env.pop(bootstrap.ButlerBootstrap._ENV_PROJECT) | 41 self.env.pop(bootstrap.ButlerBootstrap._ENV_PROJECT) |
40 self.assertRaises(bootstrap.NotBootstrappedError, | 42 self.assertRaises(bootstrap.NotBootstrappedError, |
41 bootstrap.ButlerBootstrap.probe, env=self.env) | 43 bootstrap.ButlerBootstrap.probe, env=self.env) |
42 | 44 |
43 def testProbeMissingPrefixRaisesError(self): | 45 def testProbeMissingPrefixRaisesError(self): |
44 self.env.pop(bootstrap.ButlerBootstrap._ENV_PREFIX) | 46 self.env.pop(bootstrap.ButlerBootstrap._ENV_PREFIX) |
45 self.assertRaises(bootstrap.NotBootstrappedError, | 47 self.assertRaises(bootstrap.NotBootstrappedError, |
46 bootstrap.ButlerBootstrap.probe, env=self.env) | 48 bootstrap.ButlerBootstrap.probe, env=self.env) |
47 | 49 |
48 def testProbeInvalidPrefixRaisesError(self): | 50 def testProbeInvalidPrefixRaisesError(self): |
49 self.env[bootstrap.ButlerBootstrap._ENV_PREFIX] = '!!! not valid !!!' | 51 self.env[bootstrap.ButlerBootstrap._ENV_PREFIX] = '!!! not valid !!!' |
50 self.assertRaises(bootstrap.NotBootstrappedError, | 52 self.assertRaises(bootstrap.NotBootstrappedError, |
51 bootstrap.ButlerBootstrap.probe, env=self.env) | 53 bootstrap.ButlerBootstrap.probe, env=self.env) |
52 | 54 |
| 55 def testCreateStreamClient(self): |
| 56 class TestStreamClient(stream.StreamClient): |
| 57 @classmethod |
| 58 def _create(cls, _value, **kwargs): |
| 59 return cls(**kwargs) |
| 60 |
| 61 def _connect_raw(self): |
| 62 raise NotImplementedError() |
| 63 |
| 64 reg = stream.StreamProtocolRegistry() |
| 65 reg.register_protocol('test', TestStreamClient) |
| 66 bs = bootstrap.ButlerBootstrap( |
| 67 project='test-project', |
| 68 prefix='foo/bar', |
| 69 streamserver_uri='test:', |
| 70 coordinator_host='example.appspot.com') |
| 71 sc = bs.stream_client(reg=reg) |
| 72 self.assertEqual(sc.prefix, 'foo/bar') |
| 73 self.assertEqual(sc.coordinator_host, 'example.appspot.com') |
| 74 |
53 | 75 |
54 if __name__ == '__main__': | 76 if __name__ == '__main__': |
55 unittest.main() | 77 unittest.main() |
OLD | NEW |