-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathdefer_test.go
89 lines (83 loc) · 2.15 KB
/
defer_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
package runn
import (
"context"
"testing"
)
func TestDeferRun(t *testing.T) {
tests := []struct {
book string
}{
{"testdata/book/defer.yml"},
{"testdata/book/defer_map.yml"},
}
for _, tt := range tests {
t.Run(tt.book, func(t *testing.T) {
ctx := context.Background()
o, err := New(Book(tt.book))
if err != nil {
t.Fatal(err)
}
if err := o.Run(ctx); err == nil {
t.Fatal("expected error")
}
if want := 8; o.store.StepLen() != want {
t.Errorf("o.store.StepLen() got %v, want %v", o.store.StepLen(), want)
}
r := o.Result()
if want := 8; len(r.StepResults) != want {
t.Errorf("r.StepResults got %v, want %v", len(r.StepResults), want)
}
t.Run("main steps", func(t *testing.T) {
wantResults := []struct {
desc string
skipped bool
err bool
}{
{"step 1", false, false},
{"include step", false, false},
{"step 2", false, false},
{"step 3", false, true},
{"step 4", true, false},
{"defererd step c", false, false},
{"defererd step b", false, true},
{"defererd step a", false, false},
}
for i, want := range wantResults {
got := r.StepResults[i]
if got.Desc != want.desc {
t.Errorf("got %v, want %v", got.Desc, want.desc)
}
if got.Skipped != want.skipped {
t.Errorf("got %v, want %v", got.Skipped, want.skipped)
}
if (got.Err == nil) == want.err {
t.Errorf("got %v, want %v", got.Err, want.err)
}
}
})
t.Run("include steps", func(t *testing.T) {
wantResults := []struct {
desc string
skipped bool
err bool
}{
{"included step 1", false, false},
{"included step 2", false, false},
{"included defererd step d", false, false},
}
for i, want := range wantResults {
got := r.StepResults[1].IncludedRunResults[0].StepResults[i]
if got.Desc != want.desc {
t.Errorf("got %v, want %v", got.Desc, want.desc)
}
if got.Skipped != want.skipped {
t.Errorf("got %v, want %v", got.Skipped, want.skipped)
}
if (got.Err == nil) == want.err {
t.Errorf("got %v, want %v", got.Err, want.err)
}
}
})
})
}
}