forked from k1LoW/runn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_test.go
50 lines (48 loc) · 955 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
50
package runn
import (
"context"
"errors"
"testing"
)
func TestTestRun(t *testing.T) {
tests := []struct {
cond string
wantErr interface{}
}{
{"vars.foo.bar == 'baz'", nil},
{"vars.foo.bar == 'xxx'", &condFalseError{}},
{"steps[0].res.status == 403", nil},
{"current.res.status == 403", nil},
}
ctx := context.Background()
for _, tt := range tests {
t.Run(tt.cond, func(t *testing.T) {
o, err := New(Var("foo", map[string]interface{}{
"bar": "baz",
}))
o.store.steps = []map[string]interface{}{
{
"res": map[string]interface{}{
"status": 403,
},
},
}
if err != nil {
t.Fatal(err)
}
r, err := newTestRunner(o)
if err != nil {
t.Fatal(err)
}
if err := r.Run(ctx, tt.cond); 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")
}
})
}
}