-
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.
adding tests and updating props in stages
- Loading branch information
1 parent
a17508e
commit 1f05515
Showing
11 changed files
with
369 additions
and
19 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
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
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
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,56 @@ | ||
import * as cdk from "aws-cdk-lib"; | ||
import * as events from "aws-cdk-lib/aws-events"; | ||
import * as sfn from "aws-cdk-lib/aws-stepfunctions"; | ||
import { Construct } from "constructs"; | ||
|
||
import { StateMachineStage, StateMachineStageProps } from "../src"; | ||
|
||
class TestSFNStage extends StateMachineStage { | ||
readonly targets?: events.IRuleTarget[]; | ||
readonly eventPattern?: events.EventPattern; | ||
readonly stateMachine: sfn.StateMachine; | ||
|
||
constructor(scope: Construct, id: string, props: StateMachineStageProps) { | ||
super(scope, id, props); | ||
({ | ||
eventPattern: this.eventPattern, | ||
targets: this.targets, | ||
stateMachine: this.stateMachine, | ||
} = this.createStateMachine({ | ||
definition: props.definition, | ||
definitionFile: props.definitionFile, | ||
...props, | ||
})); | ||
} | ||
} | ||
|
||
test("State Machine Stage Definition File", () => { | ||
const stack = new cdk.Stack(); | ||
new TestSFNStage(stack, "MySFN", { | ||
definitionFile: "./test/test-sfn-config.json", | ||
}); | ||
}); | ||
|
||
test("State Machine Stage Definition String", () => { | ||
const stack = new cdk.Stack(); | ||
new TestSFNStage(stack, "MySFN", { | ||
definition: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', | ||
}); | ||
}); | ||
|
||
test("SFN No Definition", () => { | ||
const stack = new cdk.Stack(); | ||
expect(() => { | ||
new TestSFNStage(stack, "MySFN", {}); | ||
}).toThrowError("One of 'definition' or 'definitionFile' must be provided."); | ||
}); | ||
|
||
test("SFN Redundant Definitions", () => { | ||
const stack = new cdk.Stack(); | ||
expect(() => { | ||
new TestSFNStage(stack, "MySFN", { | ||
definition: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}', | ||
definitionFile: "./test/test-sfn-config.json", | ||
}); | ||
}).toThrowError("Only one of 'definition' or 'definitionFile' should be provided."); | ||
}); |
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,94 @@ | ||
{ | ||
"StartAt": "random-number-generator-lambda-config", | ||
"States": { | ||
|
||
|
||
"random-number-generator-lambda-config": { | ||
"Comment": "To configure the random-number-generator-lambda.", | ||
"Type": "Pass", | ||
"Result": { | ||
"min": 1, | ||
"max": 10 | ||
}, | ||
"ResultPath": "$", | ||
"Next": "random-number-generator-lambda" | ||
}, | ||
|
||
|
||
"random-number-generator-lambda": { | ||
"Comment": "Generate a number based on input.", | ||
"Type": "Task", | ||
"Resource": "${random-number-generator-lambda-aws-arn}", | ||
"Next": "send-notification-if-less-than-5" | ||
}, | ||
|
||
|
||
"send-notification-if-less-than-5": { | ||
"Comment": "A choice state to decide to send out notification for <5 or trigger power of three lambda for >5.", | ||
"Type": "Choice", | ||
"Choices": [ | ||
{ | ||
"Variable": "$", | ||
"NumericGreaterThanEquals": 5, | ||
"Next": "power-of-three-lambda" | ||
}, | ||
{ | ||
"Variable": "$", | ||
"NumericLessThan": 5, | ||
"Next": "send-multiple-notification" | ||
} | ||
] | ||
}, | ||
|
||
|
||
"power-of-three-lambda": { | ||
"Comment": "Increase the input to power of 3 with customized input.", | ||
"Type": "Task", | ||
"Parameters" : { | ||
"base.$": "$", | ||
"exponent": 3 | ||
}, | ||
"Resource": "${power-of-number-lambda-aws-arn}", | ||
"End": true | ||
}, | ||
|
||
|
||
"send-multiple-notification": { | ||
"Comment": "Trigger multiple notification using AWS SNS", | ||
"Type": "Parallel", | ||
"End": true, | ||
"Branches": [ | ||
{ | ||
"StartAt": "send-sms-notification", | ||
"States": { | ||
"send-sms-notification": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"Message": "SMS: Random number is less than 5 $", | ||
"PhoneNumber": "${valid-handphone-number}" | ||
}, | ||
"End": true | ||
} | ||
} | ||
}, | ||
{ | ||
"StartAt": "send-sns-topic", | ||
"States": { | ||
"send-sns-topic": { | ||
"Type": "Task", | ||
"Resource": "arn:aws:states:::sns:publish", | ||
"Parameters": { | ||
"Message": "Email: Random number is less than 5: $", | ||
"TopicArn": "${aws-sns-topic-to-send-out-email}" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
|
||
} | ||
} |