Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize requirements check for system tests. #1042

Merged
merged 1 commit into from
Aug 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions system_tests/run_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
34 changes: 22 additions & 12 deletions system_tests/system_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,40 @@
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


# 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

This comment was marked as spam.

"""


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)