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

Side by Side Diff: appengine/swarming/server/config_test.py

Issue 1946253003: swarming: refactor cipd input (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@default-isolate-server
Patch Set: fix import google.protobuf Created 4 years, 7 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 unified diff | Download patch
OLDNEW
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 by the Apache v2.0 license that can be 3 # Use of this source code is governed by the Apache v2.0 license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import logging 6 import logging
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 import test_env 10 import test_env
11 test_env.setup_test_env() 11 test_env.setup_test_env()
12 12
13 from components.config import validation 13 from components.config import validation
14 from test_support import test_case 14 from test_support import test_case
15 15
16 from proto import config_pb2 16 from proto import config_pb2
17 from server import config 17 from server import config
18 18
19 19
20 # pylint: disable=W0212,W0612 20 # pylint: disable=W0212,W0612
21 21
22 22
23 class ConfigTest(test_case.TestCase): 23 class ConfigTest(test_case.TestCase):
24 def validator_test(self, validator, cfg, messages):
25 ctx = validation.Context()
26 validator(cfg, ctx)
27 self.assertEquals(ctx.result().messages, [
28 validation.Message(severity=logging.ERROR, text=m)
29 for m in messages
30 ])
31
24 def test_validate_isolate_settings(self): 32 def test_validate_isolate_settings(self):
25 def validate(**cfg): 33 self.validator_test(
26 cfg = config_pb2.IsolateSettings(**cfg) 34 config.validate_isolate_settings,
27 ctx = validation.Context.raise_on_error() 35 config_pb2.IsolateSettings(
28 config.validate_isolate_settings(cfg, ctx) 36 default_server='https://isolateserver.appspot.com'),
37 [
38 ('either specify both default_server and default_namespace or '
39 'none'),
40 ])
29 41
30 with self.assertRaises(ValueError): 42 self.validator_test(
31 # No namespace. 43 config.validate_isolate_settings,
32 validate(default_server='https://isolateserver.appspot.com') 44 config_pb2.IsolateSettings(
33 with self.assertRaises(ValueError): 45 default_server='isolateserver.appspot.com',
34 # Not a URL. 46 default_namespace='abc',
35 validate( 47 ),
36 default_server='isolateserver.appspot.com', 48 [
37 default_namespace='abc' 49 'default_server must start with "https://" or "http://"',
38 ) 50 ])
39 validate( 51
40 default_server='https://isolateserver.appspot.com', 52 self.validator_test(
41 default_namespace='default-gzip' 53 config.validate_isolate_settings,
42 ) 54 config_pb2.IsolateSettings(
43 validate() 55 default_server='https://isolateserver.appspot.com',
56 default_namespace='abc',
57 ),
58 [])
59
60 self.validator_test(
61 config.validate_isolate_settings,
62 config_pb2.IsolateSettings(),
63 [])
64
65 def test_validate_cipd_settings(self):
66 self.validator_test(
67 config.validate_cipd_settings,
68 config_pb2.CipdSettings(),
69 [
70 'server_host is not set',
71 'invalid client_package_name ""',
72 'invalid client_package_version ""',
73 ])
74
75 self.validator_test(
76 config.validate_cipd_settings,
77 config_pb2.CipdSettings(
78 server_host='chrome-infra-packages.appspot.com',
79 client_package_name='infra/tools/cipd/windows-i386',
80 client_package_version='git_revision:deadbeef'),
81 [
82 'client_package_name does not use ${platform} parameter',
83 ])
84
85 self.validator_test(
86 config.validate_cipd_settings,
87 config_pb2.CipdSettings(
88 server_host='chrome-infra-packages.appspot.com',
89 client_package_name='infra/tools/cipd/${platform}',
90 client_package_version='git_revision:deadbeef'),
91 [])
44 92
45 def test_validate_settings(self): 93 def test_validate_settings(self):
46 def validate(**cfg): 94 self.validator_test(
47 cfg = config_pb2.SettingsCfg(**cfg) 95 config.validate_settings,
48 ctx = validation.Context.raise_on_error() 96 config_pb2.SettingsCfg(
49 config.validate_settings(cfg, ctx) 97 bot_death_timeout_secs=-1,
98 reusable_task_age_secs=-1),
99 [
100 'bot_death_timeout_secs cannot be negative',
101 'reusable_task_age_secs cannot be negative',
102 ])
50 103
51 with self.assertRaises(ValueError): 104 self.validator_test(
52 validate(bot_death_timeout_secs=-1) 105 config.validate_settings,
53 with self.assertRaises(ValueError): 106 config_pb2.SettingsCfg(
54 validate(bot_death_timeout_secs=config.SECONDS_IN_YEAR + 1) 107 bot_death_timeout_secs=config.SECONDS_IN_YEAR + 1,
55 with self.assertRaises(ValueError): 108 reusable_task_age_secs=config.SECONDS_IN_YEAR + 1),
56 validate(reusable_task_age_secs=-1) 109 [
57 with self.assertRaises(ValueError): 110 'bot_death_timeout_secs cannot be more than a year',
58 validate(reusable_task_age_secs=config.SECONDS_IN_YEAR + 1) 111 'reusable_task_age_secs cannot be more than a year',
59 validate() 112 ])
113
114 self.validator_test(config.validate_settings, config_pb2.SettingsCfg(), [])
60 115
61 116
62 if __name__ == '__main__': 117 if __name__ == '__main__':
63 if '-v' in sys.argv: 118 if '-v' in sys.argv:
64 unittest.TestCase.maxDiff = None 119 unittest.TestCase.maxDiff = None
65 logging.basicConfig( 120 logging.basicConfig(
66 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) 121 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
67 unittest.main() 122 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698