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

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: rebased 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
« no previous file with comments | « appengine/swarming/server/config.py ('k') | appengine/swarming/server/task_request.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'default_server is not set',
71 'default_client_package: invalid package_name ""',
72 'default_client_package: invalid version ""',
73 ])
74
75 self.validator_test(
76 config.validate_cipd_settings,
77 config_pb2.CipdSettings(
78 default_server='chrome-infra-packages.appspot.com',
79 default_client_package=config_pb2.CipdPackage(
80 package_name='infra/tools/cipd/windows-i386',
81 version='git_revision:deadbeef'),
82 ),
83 [
84 'default_server must start with "https://" or "http://"',
85 ])
86
87 self.validator_test(
88 config.validate_cipd_settings,
89 config_pb2.CipdSettings(
90 default_server='https://chrome-infra-packages.appspot.com',
91 default_client_package=config_pb2.CipdPackage(
92 package_name='infra/tools/cipd/${platform}',
93 version='git_revision:deadbeef'),
94 ),
95 [])
44 96
45 def test_validate_settings(self): 97 def test_validate_settings(self):
46 def validate(**cfg): 98 self.validator_test(
47 cfg = config_pb2.SettingsCfg(**cfg) 99 config.validate_settings,
48 ctx = validation.Context.raise_on_error() 100 config_pb2.SettingsCfg(
49 config.validate_settings(cfg, ctx) 101 bot_death_timeout_secs=-1,
102 reusable_task_age_secs=-1),
103 [
104 'bot_death_timeout_secs cannot be negative',
105 'reusable_task_age_secs cannot be negative',
106 ])
50 107
51 with self.assertRaises(ValueError): 108 self.validator_test(
52 validate(bot_death_timeout_secs=-1) 109 config.validate_settings,
53 with self.assertRaises(ValueError): 110 config_pb2.SettingsCfg(
54 validate(bot_death_timeout_secs=config.SECONDS_IN_YEAR + 1) 111 bot_death_timeout_secs=config.SECONDS_IN_YEAR + 1,
55 with self.assertRaises(ValueError): 112 reusable_task_age_secs=config.SECONDS_IN_YEAR + 1),
56 validate(reusable_task_age_secs=-1) 113 [
57 with self.assertRaises(ValueError): 114 'bot_death_timeout_secs cannot be more than a year',
58 validate(reusable_task_age_secs=config.SECONDS_IN_YEAR + 1) 115 'reusable_task_age_secs cannot be more than a year',
59 validate() 116 ])
117
118 self.validator_test(config.validate_settings, config_pb2.SettingsCfg(), [])
60 119
61 120
62 if __name__ == '__main__': 121 if __name__ == '__main__':
63 if '-v' in sys.argv: 122 if '-v' in sys.argv:
64 unittest.TestCase.maxDiff = None 123 unittest.TestCase.maxDiff = None
65 logging.basicConfig( 124 logging.basicConfig(
66 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) 125 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
67 unittest.main() 126 unittest.main()
OLDNEW
« no previous file with comments | « appengine/swarming/server/config.py ('k') | appengine/swarming/server/task_request.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698