This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmap_state_test.go
146 lines (130 loc) · 3.75 KB
/
map_state_test.go
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package machine
import (
"github.com/coinbase/step/utils/to"
"github.com/stretchr/testify/assert"
"testing"
)
/////////
// Helpers
/////////
func initialize_state_machine(state *StateMachine, t *testing.T) {
state.StartAt = to.Strp("Start")
state.States = States{}
sm := parseTaskState([]byte(`{
"Resource": "asd",
"Next": "Pass",
"Retry": [{ "ErrorEquals": ["States.ALL"] }]
}`), t)
state.States["start"] = sm
}
// Execution
func Test_MapState_ValidateResource(t *testing.T) {
state := parseMapState([]byte(`{ "Next": "Pass"}`), t)
assert.Error(t, state.Validate())
state.Iterator = &StateMachine{}
assert.Error(t, state.Validate())
initialize_state_machine(state.Iterator, t)
assert.NoError(t, state.Validate())
}
func Test_MapState_SingleState(t *testing.T) {
state := parseMapState([]byte(`{
"Type": "Map",
"ItemsPath": "$.shipped",
"ResultPath": "$.output.data",
"OutputPath": "$.output",
"MaxConcurrency": 0,
"Iterator": {
"StartAt": "Validate",
"States": {
"Validate": {
"Type": "Pass",
"Result": {"key": "value"},
"End": true
}
}
},
"End": true
}`), t)
// Default
outputResults := map[string]interface{}{}
var res []map[string]interface{}
res = append(res, map[string]interface{}{"key": "value"})
res = append(res, map[string]interface{}{"key": "value"})
res = append(res, map[string]interface{}{"key": "value"})
outputResults["data"] = res
testState(state, stateTestData{
Input: map[string]interface{}{"shipped": []interface{}{1, 2, 3}, "output": []interface{}{}},
Output: outputResults,
}, t)
testState(state, stateTestData{
Input: map[string]interface{}{},
Error: to.Strp("GetSlice Error \"Not Found\""),
}, t)
}
func Test_MapState_Catch(t *testing.T) {
state := parseMapState([]byte(`{
"Type": "Map",
"ItemsPath": "$.shipped",
"ResultPath": "$.output.data",
"OutputPath": "$.output",
"MaxConcurrency": 0,
"Catch": [{
"ErrorEquals": ["States.ALL"],
"Next": "Fail"
}],
"Iterator": {
"StartAt": "Validate",
"States": {
"Validate": {
"Type": "Pass",
"Result": {"key": "value"},
"End": true
}
}
},
"End": true
}`), t)
// No Input path data. Should be caught
testState(state, stateTestData{
Input: map[string]interface{}{},
Output: map[string]interface{}{"Error": "errorString", "Cause": "GetSlice Error \"Not Found\""},
}, t)
}
func Test_MapState_Integration(t *testing.T) {
state := parseMapState([]byte(`{
"Type": "Map",
"ItemsPath": "$.shipped",
"ResultPath": "$.output.data",
"OutputPath": "$.output",
"MaxConcurrency": 0,
"Iterator": {
"StartAt": "Validate",
"States": {
"Validate": {
"Type": "Pass",
"Next": "Task"
},
"Task" : {
"Type": "TaskFn",
"Resource": "arn:aws:lambda:{{aws_region}}:{{aws_account}}:function:{{lambda_name}}",
"Result": {"key": "value"},
"End": true
}
}
},
"End": true
}`), t)
// Default
var task = state.Iterator.States["Task"].(*TaskState)
task.SetTaskHandler(ReturnInputHandler)
outputResults := map[string]interface{}{}
var res []map[string]interface{}
res = append(res, map[string]interface{}{"Task": "Task", "Input": float64(11)})
res = append(res, map[string]interface{}{"Task": "Task", "Input": float64(12)})
res = append(res, map[string]interface{}{"Task": "Task", "Input": float64(13)})
outputResults["data"] = res
testState(state, stateTestData{
Input: map[string]interface{}{"shipped": []interface{}{11, 12, 13}, "output": []interface{}{}},
Output: outputResults,
}, t)
}