forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.state-machine.ts
129 lines (111 loc) · 4.31 KB
/
test.state-machine.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { expect, haveResource } from '@aws-cdk/assert';
import * as logs from '@aws-cdk/aws-logs';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as stepfunctions from '../lib';
export = {
'Instantiate Default State Machine'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
// WHEN
new stepfunctions.StateMachine(stack, 'MyStateMachine', {
stateMachineName: "MyStateMachine",
definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass'))
});
// THEN
expect(stack).to(haveResource('AWS::StepFunctions::StateMachine', {
StateMachineName: "MyStateMachine",
DefinitionString: "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}"
}));
test.done();
},
'Instantiate Standard State Machine'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
// WHEN
new stepfunctions.StateMachine(stack, 'MyStateMachine', {
stateMachineName: "MyStateMachine",
definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')),
stateMachineType: stepfunctions.StateMachineType.STANDARD
});
// THEN
expect(stack).to(haveResource('AWS::StepFunctions::StateMachine', {
StateMachineName: "MyStateMachine",
StateMachineType: "STANDARD",
DefinitionString: "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}"
}));
test.done();
},
'Instantiate Express State Machine'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
// WHEN
new stepfunctions.StateMachine(stack, 'MyStateMachine', {
stateMachineName: "MyStateMachine",
definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')),
stateMachineType: stepfunctions.StateMachineType.EXPRESS
});
// THEN
expect(stack).to(haveResource('AWS::StepFunctions::StateMachine', {
StateMachineName: "MyStateMachine",
StateMachineType: "EXPRESS",
DefinitionString: "{\"StartAt\":\"Pass\",\"States\":{\"Pass\":{\"Type\":\"Pass\",\"End\":true}}}"
}));
test.done();
},
'log configuration'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
// WHEN
const logGroup = new logs.LogGroup(stack, 'MyLogGroup');
new stepfunctions.StateMachine(stack, 'MyStateMachine', {
definition: stepfunctions.Chain.start(new stepfunctions.Pass(stack, 'Pass')),
logs: {
destination: logGroup,
level: stepfunctions.LogLevel.FATAL,
includeExecutionData: false
}
});
// THEN
expect(stack).to(haveResource('AWS::StepFunctions::StateMachine', {
DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}',
LoggingConfiguration: {
Destinations: [{
CloudWatchLogsLogGroup: {
LogGroupArn: {
'Fn::GetAtt': ['MyLogGroup5C0DAD85', 'Arn']
}
}
}],
IncludeExecutionData: false,
Level: 'FATAL'
}
}));
expect(stack).to(haveResource('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [{
Action: [
'logs:CreateLogDelivery',
'logs:GetLogDelivery',
'logs:UpdateLogDelivery',
'logs:DeleteLogDelivery',
'logs:ListLogDeliveries',
'logs:PutResourcePolicy',
'logs:DescribeResourcePolicies',
'logs:DescribeLogGroups'
],
Effect: 'Allow',
Resource: '*'
}],
Version: '2012-10-17'
},
PolicyName: 'MyStateMachineRoleDefaultPolicyE468EB18',
Roles: [
{
Ref: 'MyStateMachineRoleD59FFEBC'
}
]
}));
test.done();
},
};