Skip to content

Commit b5832fa

Browse files
authored
#20 Validate task files must have .yml extension (#21)
1 parent c4edfc5 commit b5832fa

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lambda_cron/cli/cli_tool.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,14 @@ def validate(self):
343343
if self.cli.task_directory:
344344
all_yml_files = [os.path.join(dirpath, f)
345345
for dirpath, dirnames, files in os.walk(self.cli.task_directory)
346-
for f in files if f.endswith('.yml')]
346+
for f in files]
347347
for file_name in all_yml_files:
348+
if not file_name.endswith('.yml'):
349+
raise RuntimeError('Task is not defined in YAML file (extension .yml): {}'.format(file_name))
348350
self.validate_task(schema, file_name)
349-
except jsonschema.exceptions.ValidationError, ex:
351+
except Exception, ex:
350352
print("Validation failed! Validation error in task: {}".format(ex.message))
351353
sys.exit(1)
352-
except Exception, ex:
353-
raise ex
354354
print 'Validation success!'
355355

356356
def print_summary(self):
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: 'test queue task'
2+
expression: '0 * * * *'
3+
task:
4+
type: 'queue'
5+
QueueName: 'test-queue'
6+
MessageBody:
7+
message_key_1: 'message_value_1'
8+
message_key_2: ['message_value_2']

tests/test_cli_tool.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,18 @@ def test_validate_command_directory_error(monkeypatch):
628628
lambda_cron.run()
629629

630630
assert system_exit.value.code == 1
631+
632+
633+
def test_validate_invalid_file_extension(monkeypatch):
634+
monkeypatch.setattr(cli_config, 'get_cli_config_file_path', valid_cong_file_path)
635+
cli_params = Namespace()
636+
cli_params.command = 'validate'
637+
cli_params.task_file = get_test_task_path('invalid/invalid_extension.yml')
638+
cli_params.task_directory = None
639+
640+
lambda_cron = LambdaCronCLISpy(cli_params)
641+
642+
with pytest.raises(SystemExit) as system_exit:
643+
lambda_cron.run()
644+
645+
assert system_exit.value.code == 1

0 commit comments

Comments
 (0)