forked from aws/aws-sam-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAM Test for StepFunctions (aws#378)
* SAM test for step functions (state machine) * Fixing a typo in comment * Added missing unit test for create test executors of kinesis and stepfunctions * Refactoring to change the lambda json converter the default json converter
- Loading branch information
Showing
6 changed files
with
177 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Test executor implementation for StepFunctions | ||
""" | ||
import logging | ||
import time | ||
from typing import Any | ||
|
||
from samcli.lib.test.test_executors import BotoActionExecutor | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class StepFunctionsStartExecutionExecutor(BotoActionExecutor): | ||
""" | ||
Calls "start_execution" method of "stepfunctions" service with given input. | ||
If a file location provided, the file handle will be passed as Payload object | ||
""" | ||
|
||
_stepfunctions_client: Any | ||
_physical_id: str | ||
_state_machine_arn: str | ||
|
||
def __init__(self, stepfunctions_client: Any, physical_id: str): | ||
self._stepfunctions_client = stepfunctions_client | ||
self._state_machine_arn = physical_id | ||
|
||
def _execute_action(self, payload: str): | ||
timestamp = str(int(time.time() * 1000)) | ||
name = f"sam_test_{timestamp}" | ||
LOG.debug( | ||
"Calling stepfunctions_client.start_execution with name:%s, input:%s, stateMachineArn:%s", | ||
name, | ||
payload, | ||
self._state_machine_arn, | ||
) | ||
return self._stepfunctions_client.start_execution( | ||
name=name, input=payload, stateMachineArn=self._state_machine_arn | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import base64 | ||
|
||
from json import JSONDecodeError | ||
from typing import Any | ||
from unittest import TestCase | ||
from unittest.mock import ANY, Mock, patch | ||
|
||
from samcli.lib.test.stepfunctions_test_executor import StepFunctionsStartExecutionExecutor | ||
|
||
|
||
class TestStepFunctionsStartExecutionExecutor(TestCase): | ||
def setUp(self) -> None: | ||
self.stepfunctions_client = Mock() | ||
self.statemachine_arn = Mock() | ||
self.stepfunctions_start_execution_executor = StepFunctionsStartExecutionExecutor( | ||
self.stepfunctions_client, self.statemachine_arn | ||
) | ||
|
||
def test_execute_action(self): | ||
given_payload = Mock() | ||
given_result = Mock() | ||
self.stepfunctions_client.start_execution.return_value = given_result | ||
|
||
result = self.stepfunctions_start_execution_executor._execute_action(given_payload) | ||
|
||
self.assertEqual(result, given_result) | ||
self.stepfunctions_client.start_execution.assert_called_with( | ||
name=ANY, input=given_payload, stateMachineArn=self.statemachine_arn | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters