-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtest_test.go
49 lines (47 loc) · 981 Bytes
/
test_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
package runn
import (
"context"
"errors"
"testing"
)
func TestTestRun(t *testing.T) {
tests := []struct {
cond string
first bool
wantErr any
}{
{"vars.foo.bar == 'baz'", false, nil},
{"vars.foo.bar == 'xxx'", false, &condFalseError{}},
{"steps[0].res.status == 403", false, nil},
{"current.res.status == 403", false, nil},
}
ctx := context.Background()
for _, tt := range tests {
tt := tt
t.Run(tt.cond, func(t *testing.T) {
o, err := New(Var("foo", map[string]any{
"bar": "baz",
}))
o.store.Record(0, map[string]any{
"res": map[string]any{
"status": 403,
},
})
if err != nil {
t.Fatal(err)
}
r := newTestRunner()
s := newStep(0, "stepKey", o, nil)
s.testCond = tt.cond
if err := r.Run(ctx, s, tt.first); err != nil {
if !errors.As(err, &tt.wantErr) {
t.Errorf("got %v\nwant %v", err, tt.wantErr)
}
return
}
if tt.wantErr != nil {
t.Error("want error\n")
}
})
}
}