forked from arcalot/arcaflow-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine_test.go
179 lines (167 loc) · 3.91 KB
/
engine_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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package engine_test
import (
"context"
"errors"
"testing"
log "go.arcalot.io/log/v2"
"go.flow.arcalot.io/engine"
"go.flow.arcalot.io/engine/workflow"
"go.arcalot.io/assert"
"go.flow.arcalot.io/engine/config"
)
func createTestEngine(t *testing.T) engine.WorkflowEngine {
cfg := config.Default()
cfg.Log.T = t
cfg.Log.Level = log.LevelDebug
cfg.Log.Destination = log.DestinationTest
flow, err := engine.New(
cfg,
)
assert.NoError(t, err)
return flow
}
func TestNoWorkflowFile(t *testing.T) {
_, _, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
nil,
map[string][]byte{},
"",
)
assert.Error(t, err)
assert.Equals(t, outputError, true)
if !errors.Is(err, engine.ErrNoWorkflowFile) {
t.Fatalf("Incorrect error returned.")
}
}
func TestEmptyWorkflowFile(t *testing.T) {
_, _, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
nil,
map[string][]byte{
"workflow.yaml": {},
},
"",
)
assert.Error(t, err)
assert.Equals(t, outputError, true)
if !errors.Is(err, workflow.ErrEmptyWorkflowFile) {
t.Fatalf("Incorrect error returned.")
}
}
func TestInvalidYAML(t *testing.T) {
_, _, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
nil,
map[string][]byte{
"workflow.yaml": []byte(`: foo
bar`),
},
"",
)
assert.Error(t, err)
assert.Equals(t, outputError, true)
var invalidYAML *workflow.ErrInvalidWorkflowYAML
if !errors.As(err, &invalidYAML) {
t.Fatalf("Incorrect error returned.")
}
}
func TestInvalidWorkflow(t *testing.T) {
_, _, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
nil,
map[string][]byte{
"workflow.yaml": []byte(`test: Hello world!`),
},
"",
)
assert.Error(t, err)
assert.Equals(t, outputError, true)
var invalidYAML *workflow.ErrInvalidWorkflow
if !errors.As(err, &invalidYAML) {
t.Fatalf("Incorrect error returned.")
}
}
func TestEmptySteps(t *testing.T) {
_, _, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
nil,
map[string][]byte{
"workflow.yaml": []byte(`output: []
steps: []`),
},
"",
)
assert.Error(t, err)
assert.Equals(t, outputError, true)
}
func TestNoSteps(t *testing.T) {
_, _, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
nil,
map[string][]byte{
"workflow.yaml": []byte(`output: []`),
},
"",
)
assert.Error(t, err)
assert.Equals(t, outputError, true)
}
func TestE2E(t *testing.T) {
outputID, outputData, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
[]byte(`name: Arca Lot`),
map[string][]byte{
"workflow.yaml": []byte(`input:
root: RootObject
objects:
RootObject:
id: RootObject
properties:
name:
type:
type_id: string
steps:
example:
plugin: ghcr.io/janosdebugs/arcaflow-example-plugin
input:
name: !expr $.input.name
output:
message: !expr $.steps.example.outputs.success.message`),
},
"",
)
assert.NoError(t, err)
assert.Equals(t, outputError, false)
assert.Equals(t, outputID, "success")
assert.Equals(t, outputData.(map[any]any), map[any]any{"message": "Hello, Arca Lot!"})
}
func TestE2EMultipleOutputs(t *testing.T) {
outputID, outputData, outputError, err := createTestEngine(t).RunWorkflow(
context.Background(),
[]byte(`name: Arca Lot`),
map[string][]byte{
"workflow.yaml": []byte(`input:
root: RootObject
objects:
RootObject:
id: RootObject
properties:
name:
type:
type_id: string
steps:
example:
plugin: ghcr.io/janosdebugs/arcaflow-example-plugin
input:
name: !expr $.input.name
outputs:
success:
message: !expr $.steps.example.outputs.success.message`),
},
"",
)
assert.NoError(t, err)
assert.Equals(t, outputError, false)
assert.Equals(t, outputID, "success")
assert.Equals(t, outputData.(map[any]any), map[any]any{"message": "Hello, Arca Lot!"})
}