forked from k1LoW/runn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinclude_test.go
More file actions
125 lines (120 loc) · 2.56 KB
/
Copy pathinclude_test.go
File metadata and controls
125 lines (120 loc) · 2.56 KB
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
package runn
import (
"context"
"fmt"
"os"
"testing"
)
func TestIncludeRunnerRun(t *testing.T) {
tests := []struct {
path string
vars map[string]interface{}
want int
}{
{"testdata/book/db.yml", map[string]interface{}{}, 8},
{"testdata/book/db.yml", map[string]interface{}{"foo": "bar"}, 8},
{"testdata/book/db.yml", map[string]interface{}{"json": "json://../vars.json"}, 8},
}
ctx := context.Background()
for _, tt := range tests {
db, err := os.CreateTemp("", "tmp")
if err != nil {
t.Fatal(err)
}
defer os.Remove(db.Name())
o, err := New(Runner("db", fmt.Sprintf("sqlite://%s", db.Name())))
if err != nil {
t.Fatal(err)
}
r, err := newIncludeRunner(o)
if err != nil {
t.Fatal(err)
}
c := &includeConfig{path: tt.path, vars: tt.vars}
if err := r.Run(ctx, c); err != nil {
t.Fatal(err)
}
t.Run("step length", func(t *testing.T) {
{
got := len(r.operator.store.steps)
if want := 1; got != want {
t.Errorf("got %v\nwant %v", got, want)
}
}
{
got := len(r.operator.store.steps[0]["steps"].([]map[string]interface{}))
if got != tt.want {
t.Errorf("got %v\nwant %v", got, tt.want)
}
}
})
t.Run("var length", func(t *testing.T) {
{
got := len(r.operator.store.vars)
if want := 0; got != want {
t.Errorf("got %v\nwant %v", got, want)
}
}
{
got := len(r.operator.store.steps[0]["vars"].(map[string]interface{}))
if want := len(tt.vars); got != want {
t.Errorf("got %v\nwant %v", got, want)
}
}
})
}
}
func TestMultipleIncludeRunnerRun(t *testing.T) {
tests := []struct {
path string
vars map[string]interface{}
}{
{
"testdata/book/multiple_include_a.yml",
map[string]interface{}{
"foo": 123,
"bar": "123-abc",
"baz": "-23",
"qux": 4,
"quxx": "2",
"corge": map[string]interface{}{
"grault": "1234",
"garply": 1234,
},
"waldo": true,
"fred": "false",
},
},
{
"testdata/book/multiple_include_main.yml",
map[string]interface{}{
"foo": 123,
"bar": "abc",
"baz": 100,
"qux": -1,
"quxx": 2,
"corge": map[string]interface{}{
"grault": "1234",
"garply": 1234,
},
"waldo": true,
"fred": "false",
},
},
}
ctx := context.Background()
for _, tt := range tests {
o, err := New(Runner("req", "https://example.com"))
if err != nil {
t.Fatal(err)
}
r, err := newIncludeRunner(o)
if err != nil {
t.Fatal(err)
}
c := &includeConfig{path: tt.path, vars: tt.vars}
if err := r.Run(ctx, c); err != nil {
t.Fatal(err)
}
}
}