| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import logging |
| 7 import sys |
| 8 import unittest |
| 9 |
| 10 import test_env |
| 11 test_env.setup_test_env() |
| 12 |
| 13 from components.config import validation |
| 14 from test_support import test_case |
| 15 |
| 16 from proto import config_pb2 |
| 17 from server import config |
| 18 |
| 19 |
| 20 # pylint: disable=W0212,W0612 |
| 21 |
| 22 |
| 23 class ConfigTest(test_case.TestCase): |
| 24 def test_validate_isolate_settings(self): |
| 25 def validate(**cfg): |
| 26 cfg = config_pb2.IsolateSettings(**cfg) |
| 27 ctx = validation.Context.raise_on_error() |
| 28 config.validate_isolate_settings(cfg, ctx) |
| 29 |
| 30 with self.assertRaises(ValueError): |
| 31 # No namespace. |
| 32 validate(default_server='https://isolateserver.appspot.com') |
| 33 with self.assertRaises(ValueError): |
| 34 # Not a URL. |
| 35 validate( |
| 36 default_server='isolateserver.appspot.com', |
| 37 default_namespace='abc' |
| 38 ) |
| 39 validate( |
| 40 default_server='https://isolateserver.appspot.com', |
| 41 default_namespace='default-gzip' |
| 42 ) |
| 43 validate() |
| 44 |
| 45 def test_validate_settings(self): |
| 46 def validate(**cfg): |
| 47 cfg = config_pb2.SettingsCfg(**cfg) |
| 48 ctx = validation.Context.raise_on_error() |
| 49 config.validate_settings(cfg, ctx) |
| 50 |
| 51 with self.assertRaises(ValueError): |
| 52 validate(bot_death_timeout_secs=-1) |
| 53 with self.assertRaises(ValueError): |
| 54 validate(bot_death_timeout_secs=config.SECONDS_IN_YEAR + 1) |
| 55 with self.assertRaises(ValueError): |
| 56 validate(reusable_task_age_secs=-1) |
| 57 with self.assertRaises(ValueError): |
| 58 validate(reusable_task_age_secs=config.SECONDS_IN_YEAR + 1) |
| 59 validate() |
| 60 |
| 61 |
| 62 if __name__ == '__main__': |
| 63 if '-v' in sys.argv: |
| 64 unittest.TestCase.maxDiff = None |
| 65 logging.basicConfig( |
| 66 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
| 67 unittest.main() |
| OLD | NEW |