-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
runner_runner_test.go
119 lines (115 loc) · 2.1 KB
/
runner_runner_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
package runn
import (
"context"
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/k1LoW/donegroup"
"github.com/samber/lo"
)
func TestRunnerRunner(t *testing.T) {
type runnerKeys struct {
http []string
db []string
grpc []string
cdp []string
ssh []string
}
tests := []struct {
definition map[string]any
want runnerKeys
wantErr bool
}{
{
nil,
runnerKeys{},
true,
},
{
map[string]any{
"req": "https://example.com",
},
runnerKeys{
http: []string{"req"},
db: []string{},
grpc: []string{},
cdp: []string{},
ssh: []string{},
},
false,
},
{
map[string]any{
"req": "https://example.com",
"db": "sqlite3://:memory:",
},
runnerKeys{},
true,
},
{
map[string]any{
"req": map[string]any{
"endpoint": "https://example.com",
},
},
runnerKeys{
http: []string{"req"},
db: []string{},
grpc: []string{},
cdp: []string{},
ssh: []string{},
},
false,
},
{
map[string]any{
"db": "sqlite3://:memory:",
},
runnerKeys{
http: []string{},
db: []string{"db"},
grpc: []string{},
cdp: []string{},
ssh: []string{},
},
false,
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%v", tt.definition), func(t *testing.T) {
ctx, cancel := donegroup.WithCancel(context.Background())
t.Cleanup(cancel)
t.Parallel()
o, err := New()
if err != nil {
t.Fatal(err)
}
rnr := newRunnerRunner()
s := newStep(0, "stepKey", o, nil)
s.runnerDefinition = tt.definition
if err := rnr.Run(ctx, s); err != nil {
if !tt.wantErr {
t.Errorf("unexpected error: %v", err)
}
return
}
if tt.wantErr {
t.Error("want error, but no error")
return
}
got := runnerKeys{
http: lo.Keys(o.httpRunners),
db: lo.Keys(o.dbRunners),
grpc: lo.Keys(o.grpcRunners),
cdp: lo.Keys(o.cdpRunners),
ssh: lo.Keys(o.sshRunners),
}
opts := []cmp.Option{
cmp.AllowUnexported(runnerKeys{}),
}
if diff := cmp.Diff(got, tt.want, opts...); diff != "" {
t.Error(diff)
}
})
}
}