diff --git a/system_tests/run_system_test.py b/system_tests/run_system_test.py index 612c35c967d5..ab284ed5936c 100644 --- a/system_tests/run_system_test.py +++ b/system_tests/run_system_test.py @@ -20,12 +20,18 @@ # repository root is the current directory. from system_tests import system_test_utils +REQUIREMENTS = { + 'datastore': ['dataset_id', 'credentials'], + 'storage': ['project', 'credentials'], + 'pubsub': ['project', 'credentials'], +} + def get_parser(): parser = argparse.ArgumentParser( description='GCloud test runner against actual project.') parser.add_argument('--package', dest='package', - choices=('datastore', 'storage', 'pubsub'), + choices=REQUIREMENTS.keys(), default='datastore', help='Package to be tested.') return parser @@ -41,14 +47,9 @@ def main(): parser = get_parser() args = parser.parse_args() # Make sure environ is set before running test. - if args.package == 'datastore': - system_test_utils.check_environ(require_datastore=True) - elif args.package == 'storage': - system_test_utils.check_environ(require_storage=True) - elif args.package == 'pubsub': - system_test_utils.check_environ(require_pubsub=True) - else: - raise ValueError('Unexpected package name.') + requirements = REQUIREMENTS[args.package] + system_test_utils.check_environ(*requirements) + test_result = run_module_tests(args.package) if not test_result.wasSuccessful(): sys.exit(1) diff --git a/system_tests/system_test_utils.py b/system_tests/system_test_utils.py index 4d497b8020d4..0c8425ea742f 100644 --- a/system_tests/system_test_utils.py +++ b/system_tests/system_test_utils.py @@ -16,7 +16,7 @@ import os import sys -from gcloud.environment_vars import CREDENTIALS +from gcloud.environment_vars import CREDENTIALS as TEST_CREDENTIALS from gcloud.environment_vars import TESTS_DATASET from gcloud.environment_vars import TESTS_PROJECT @@ -24,22 +24,32 @@ # From shell environ. May be None. PROJECT_ID = os.getenv(TESTS_PROJECT) DATASET_ID = os.getenv(TESTS_DATASET) -CREDENTIALS = os.getenv(CREDENTIALS) +CREDENTIALS = os.getenv(TEST_CREDENTIALS) ENVIRON_ERROR_MSG = """\ To run the system tests, you need to set some environment variables. Please check the CONTRIBUTING guide for instructions. + +Missing variables: %s """ -def check_environ(require_datastore=False, require_storage=False, - require_pubsub=False): - if require_datastore: - if DATASET_ID is None or not os.path.isfile(CREDENTIALS): - print(ENVIRON_ERROR_MSG, file=sys.stderr) - sys.exit(1) +def check_environ(*requirements): + + missing = [] + + if 'dataset_id' in requirements: + if DATASET_ID is None: + missing.append(TESTS_DATASET) + + if 'project' in requirements: + if PROJECT_ID is None: + missing.append(TESTS_PROJECT) + + if 'credentials' in requirements: + if CREDENTIALS is None or not os.path.isfile(CREDENTIALS): + missing.append(TEST_CREDENTIALS) - if require_storage or require_pubsub: - if PROJECT_ID is None or not os.path.isfile(CREDENTIALS): - print(ENVIRON_ERROR_MSG, file=sys.stderr) - sys.exit(1) + if missing: + print(ENVIRON_ERROR_MSG % ', '.join(missing), file=sys.stderr) + sys.exit(1)