Only guard repository when --extract is used.

This commit is contained in:
Dan Helfman 2019-02-18 21:43:30 -08:00
parent 36305c50b1
commit c35f90154f
2 changed files with 16 additions and 7 deletions

View file

@ -403,6 +403,7 @@ def collect_configuration_run_summary_logs(config_filenames, args):
) )
yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error)) yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error))
if args.extract:
validate.guard_configuration_contains_repository(args.repository, configs) validate.guard_configuration_contains_repository(args.repository, configs)
for config_filename, config in configs.items(): for config_filename, config in configs.items():

View file

@ -48,10 +48,20 @@ def test_run_commands_handles_multiple_json_outputs_in_array():
def test_collect_configuration_run_summary_logs_info_for_success(): def test_collect_configuration_run_summary_logs_info_for_success():
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
flexmock(module).should_receive('run_configuration')
args = flexmock(extract=False)
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
assert any(log for log in logs if log.levelno == module.logging.INFO)
def test_collect_configuration_run_summary_still_succeeds_when_extract_true():
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
flexmock(module.validate).should_receive('guard_configuration_contains_repository') flexmock(module.validate).should_receive('guard_configuration_contains_repository')
flexmock(module).should_receive('run_configuration') flexmock(module).should_receive('run_configuration')
args = flexmock(repository=None) args = flexmock(extract=True, repository='repo')
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
@ -60,8 +70,7 @@ def test_collect_configuration_run_summary_logs_info_for_success():
def test_collect_configuration_run_summary_logs_critical_for_parse_error(): def test_collect_configuration_run_summary_logs_critical_for_parse_error():
flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError) flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError)
flexmock(module.validate).should_receive('guard_configuration_contains_repository') args = flexmock(extract=False)
args = flexmock(repository=None)
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
@ -72,7 +81,7 @@ def test_collect_configuration_run_summary_logs_critical_for_run_error():
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
flexmock(module.validate).should_receive('guard_configuration_contains_repository') flexmock(module.validate).should_receive('guard_configuration_contains_repository')
flexmock(module).should_receive('run_configuration').and_raise(ValueError) flexmock(module).should_receive('run_configuration').and_raise(ValueError)
args = flexmock(repository=None) args = flexmock(extract=False)
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
@ -81,9 +90,8 @@ def test_collect_configuration_run_summary_logs_critical_for_run_error():
def test_collect_configuration_run_summary_logs_critical_for_missing_configs(): def test_collect_configuration_run_summary_logs_critical_for_missing_configs():
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
flexmock(module.validate).should_receive('guard_configuration_contains_repository')
flexmock(module).should_receive('run_configuration') flexmock(module).should_receive('run_configuration')
args = flexmock(config_paths=(), repository=None) args = flexmock(config_paths=(), extract=False)
logs = tuple(module.collect_configuration_run_summary_logs(config_filenames=(), args=args)) logs = tuple(module.collect_configuration_run_summary_logs(config_filenames=(), args=args))