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 pathpass_state_test.go
96 lines (72 loc) · 2.46 KB
/
pass_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
package machine
import (
"testing"
"github.com/coinbase/step/utils/to"
"github.com/stretchr/testify/assert"
)
func Test_PassState_Defaults(t *testing.T) {
state := parsePassState([]byte(`{ "Next": "Pass", "End": true}`), t)
err := state.Validate()
assert.Error(t, err)
assert.Equal(t, *state.GetType(), "Pass")
assert.Equal(t, errorPrefix(state), "PassState(TestState) Error:")
assert.Regexp(t, "End and Next both defined", err.Error())
}
// Validations
func Test_PassState_EndNextBothDefined(t *testing.T) {
state := parsePassState([]byte(`{ "Next": "Pass", "End": true}`), t)
err := state.Validate()
assert.Error(t, err)
assert.Regexp(t, "End and Next both defined", err.Error())
}
func Test_PassState_EndNextBothUnDefined(t *testing.T) {
state := parsePassState([]byte(`{}`), t)
err := state.Validate()
assert.Error(t, err)
assert.Regexp(t, "End and Next both undefined", err.Error())
}
// Execution
func Test_PassState_ResultPath(t *testing.T) {
state := parsePassState([]byte(`{ "Next": "Pass", "Result": "b", "ResultPath": "$.a"}`), t)
testState(state, stateTestData{Output: map[string]interface{}{"a": "b"}}, t)
}
func Test_PassState_ResultPathOverrwite(t *testing.T) {
state := parsePassState([]byte(`{ "Next": "Pass", "Result": "b", "ResultPath": "$.a"}`), t)
testState(state, stateTestData{
Input: map[string]interface{}{"a": "c"},
Output: map[string]interface{}{"a": "b"},
}, t)
}
func Test_PassState_InputPath(t *testing.T) {
state := parsePassState([]byte(`{"Next": "Pass", "InputPath": "$.a"}`), t)
deep := map[string]interface{}{"a": "b"}
input := map[string]interface{}{"a": deep}
testState(state, stateTestData{
Input: input,
Output: deep,
}, t)
}
func Test_PassState_OutputPath(t *testing.T) {
state := parsePassState([]byte(`{ "Next": "Pass", "OutputPath": "$.a"}`), t)
deep := map[string]interface{}{"a": "b"}
input := map[string]interface{}{"a": deep}
testState(state, stateTestData{
Input: input,
Output: deep,
}, t)
}
// Bad Execution
func Test_PassState_BadInputPath(t *testing.T) {
state := parsePassState([]byte(`{"Next": "Pass","InputPath": "$.a.b"}`), t)
testState(state, stateTestData{
Input: map[string]interface{}{"a": "b"},
Error: to.Strp("Input Error"),
}, t)
}
func Test_PassState_BadOutputPath(t *testing.T) {
state := parsePassState([]byte(`{"Next": "Pass","OutputPath": "$.a.b"}`), t)
testState(state, stateTestData{
Input: map[string]interface{}{"a": "b"},
Error: to.Strp("Output Error"),
}, t)
}