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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/server/config_test.py
diff --git a/appengine/swarming/server/config_test.py b/appengine/swarming/server/config_test.py
index a05a7640e1a781a72aa000ad6c2ddf2c5209907d..84dc564198651d685abbfe2311f84468fd71aaea 100755
--- a/appengine/swarming/server/config_test.py
+++ b/appengine/swarming/server/config_test.py
@@ -21,42 +21,97 @@ from server import config
class ConfigTest(test_case.TestCase):
+ def validator_test(self, validator, cfg, messages):
+ ctx = validation.Context()
+ validator(cfg, ctx)
+ self.assertEquals(ctx.result().messages, [
+ validation.Message(severity=logging.ERROR, text=m)
+ for m in messages
+ ])
+
def test_validate_isolate_settings(self):
- def validate(**cfg):
- cfg = config_pb2.IsolateSettings(**cfg)
- ctx = validation.Context.raise_on_error()
- config.validate_isolate_settings(cfg, ctx)
-
- with self.assertRaises(ValueError):
- # No namespace.
- validate(default_server='https://isolateserver.appspot.com')
- with self.assertRaises(ValueError):
- # Not a URL.
- validate(
- default_server='isolateserver.appspot.com',
- default_namespace='abc'
- )
- validate(
- default_server='https://isolateserver.appspot.com',
- default_namespace='default-gzip'
- )
- validate()
+ self.validator_test(
+ config.validate_isolate_settings,
+ config_pb2.IsolateSettings(
+ default_server='https://isolateserver.appspot.com'),
+ [
+ ('either specify both default_server and default_namespace or '
+ 'none'),
+ ])
+
+ self.validator_test(
+ config.validate_isolate_settings,
+ config_pb2.IsolateSettings(
+ default_server='isolateserver.appspot.com',
+ default_namespace='abc',
+ ),
+ [
+ 'default_server must start with "https://" or "http://"',
+ ])
+
+ self.validator_test(
+ config.validate_isolate_settings,
+ config_pb2.IsolateSettings(
+ default_server='https://isolateserver.appspot.com',
+ default_namespace='abc',
+ ),
+ [])
+
+ self.validator_test(
+ config.validate_isolate_settings,
+ config_pb2.IsolateSettings(),
+ [])
+
+ def test_validate_cipd_settings(self):
+ self.validator_test(
+ config.validate_cipd_settings,
+ config_pb2.CipdSettings(),
+ [
+ 'server_host is not set',
+ 'invalid client_package_name ""',
+ 'invalid client_package_version ""',
+ ])
+
+ self.validator_test(
+ config.validate_cipd_settings,
+ config_pb2.CipdSettings(
+ server_host='chrome-infra-packages.appspot.com',
+ client_package_name='infra/tools/cipd/windows-i386',
+ client_package_version='git_revision:deadbeef'),
+ [
+ 'client_package_name does not use ${platform} parameter',
+ ])
+
+ self.validator_test(
+ config.validate_cipd_settings,
+ config_pb2.CipdSettings(
+ server_host='chrome-infra-packages.appspot.com',
+ client_package_name='infra/tools/cipd/${platform}',
+ client_package_version='git_revision:deadbeef'),
+ [])
def test_validate_settings(self):
- def validate(**cfg):
- cfg = config_pb2.SettingsCfg(**cfg)
- ctx = validation.Context.raise_on_error()
- config.validate_settings(cfg, ctx)
-
- with self.assertRaises(ValueError):
- validate(bot_death_timeout_secs=-1)
- with self.assertRaises(ValueError):
- validate(bot_death_timeout_secs=config.SECONDS_IN_YEAR + 1)
- with self.assertRaises(ValueError):
- validate(reusable_task_age_secs=-1)
- with self.assertRaises(ValueError):
- validate(reusable_task_age_secs=config.SECONDS_IN_YEAR + 1)
- validate()
+ self.validator_test(
+ config.validate_settings,
+ config_pb2.SettingsCfg(
+ bot_death_timeout_secs=-1,
+ reusable_task_age_secs=-1),
+ [
+ 'bot_death_timeout_secs cannot be negative',
+ 'reusable_task_age_secs cannot be negative',
+ ])
+
+ self.validator_test(
+ config.validate_settings,
+ config_pb2.SettingsCfg(
+ bot_death_timeout_secs=config.SECONDS_IN_YEAR + 1,
+ reusable_task_age_secs=config.SECONDS_IN_YEAR + 1),
+ [
+ 'bot_death_timeout_secs cannot be more than a year',
+ 'reusable_task_age_secs cannot be more than a year',
+ ])
+
+ self.validator_test(config.validate_settings, config_pb2.SettingsCfg(), [])
if __name__ == '__main__':

Powered by Google App Engine
This is Rietveld 408576698