-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added assertion for expected state machine output.
- Loading branch information
1 parent
21ac845
commit 0558de3
Showing
2 changed files
with
60 additions
and
1 deletion.
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,57 @@ | ||
import { testResult, TestResultOutput } from "utils/testResult"; | ||
import { StepFunctions as AWSStepFunctions } from "aws-sdk"; | ||
|
||
export default { | ||
async toMatchStateMachineOutput( | ||
stateMachineName: string, | ||
expectedOutput: any | ||
): Promise<TestResultOutput> { | ||
const stepFunctions = new AWSStepFunctions(); | ||
const allStateMachines = await stepFunctions.listStateMachines().promise(); | ||
|
||
const smList = allStateMachines.stateMachines.filter( | ||
(stateMachine: any) => stateMachine.name === stateMachineName | ||
); | ||
|
||
const stateMachineArn = smList[0].stateMachineArn; | ||
const listExecParams = { stateMachineArn: stateMachineArn }; | ||
const executionList = await stepFunctions | ||
.listExecutions(listExecParams) | ||
.promise(); | ||
|
||
const executionResult = await stepFunctions | ||
.describeExecution({ | ||
executionArn: executionList.executions[0].executionArn, | ||
}) | ||
.promise(); | ||
|
||
// if (allStateMachines === undefined) { | ||
// throw new Error( | ||
// "The list of state machines is undefined. You might have forgotten to run build()." | ||
// ); | ||
// } | ||
|
||
if (executionResult.status === "SUCCEEDED") { | ||
if (executionResult.output === expectedOutput) { | ||
return testResult( | ||
`Output is ${JSON.stringify(executionResult.output)} as expected`, | ||
true | ||
); | ||
} else { | ||
return testResult( | ||
`Expected output was ${JSON.stringify( | ||
expectedOutput | ||
)}, but output received was ${JSON.stringify( | ||
executionResult.output | ||
)}`, | ||
false | ||
); | ||
} | ||
} | ||
|
||
return testResult( | ||
"Step Function execution failed. Cannot verify output for failed executions.", | ||
false | ||
); | ||
}, | ||
}; |