From c820b4935c06427428f7a32b8f05f7bce48dc658 Mon Sep 17 00:00:00 2001 From: Nicolas Harlem Eide Date: Wed, 27 Jul 2022 10:07:36 +0200 Subject: [PATCH] test: Add missing integration pattern test for ECS Task --- tests/unit/test_compute_steps.py | 65 +++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/tests/unit/test_compute_steps.py b/tests/unit/test_compute_steps.py index 8261396..b9c271b 100644 --- a/tests/unit/test_compute_steps.py +++ b/tests/unit/test_compute_steps.py @@ -101,35 +101,74 @@ def test_batch_submit_job_step_creation(): @patch.object(boto3.session.Session, 'region_name', 'us-east-1') -def test_ecs_run_task_step_creation(): - step = EcsRunTaskStep('Ecs Job', wait_for_completion=False) +@pytest.mark.parametrize( + ("task_kwargs",), + [ + ({}), + ({ + "integration_pattern": IntegrationPattern.WaitForCompletion, + "wait_for_completion": False, + }), + ] +) +def test_ecs_run_task_with_wait_for_completion(task_kwargs): + step = EcsRunTaskStep('ECS Job', **task_kwargs) + assert step.to_dict() == { 'Type': 'Task', - 'Resource': 'arn:aws:states:::ecs:runTask', + 'Resource': 'arn:aws:states:::ecs:runTask.sync', + 'Parameters': { + 'TaskDefinition': 'Task' + }, 'End': True } - step = EcsRunTaskStep('Ecs Job', - integration_pattern=IntegrationPattern.WaitForTaskToken, - wait_for_completion=False) + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +@pytest.mark.parametrize( + ("task_kwargs",), + [ + ({ + "integration_pattern": IntegrationPattern.WaitForTaskToken, + "wait_for_completion": False, + }), + ] +) +def test_ecs_run_task_with_wait_for_task_token(task_kwargs): + step = EcsRunTaskStep('ECS Job', **task_kwargs) + assert step.to_dict() == { 'Type': 'Task', 'Resource': 'arn:aws:states:::ecs:runTask.waitForTaskToken', 'End': True } - step = EcsRunTaskStep('Ecs Job', parameters={ - 'TaskDefinition': 'Task' - }) + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +@pytest.mark.parametrize( + ("task_kwargs",), + [ + ({ + "wait_for_completion": False, + }), + ({ + "integration_pattern": IntegrationPattern.CallAndContinue, + "wait_for_completion": False, + }) + ] +) +def test_ecs_run_task_with_call_and_continue(task_kwargs): + step = EcsRunTaskStep('ECS Job', **task_kwargs) + assert step.to_dict() == { 'Type': 'Task', - 'Resource': 'arn:aws:states:::ecs:runTask.sync', - 'Parameters': { - 'TaskDefinition': 'Task' - }, + 'Resource': 'arn:aws:states:::ecs:runTask', 'End': True } + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_ecs_run_task_with_conflicting_arguments(): with pytest.raises(ValueError): step = EcsRunTaskStep('Ecs Job', wait_for_completion=True,