forked from k1LoW/runn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvars_test.go
49 lines (45 loc) · 1.34 KB
/
vars_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 (
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestEvaluateSchema(t *testing.T) {
brokenJson, _ := os.CreateTemp("", "broken_json")
defer os.Remove(brokenJson.Name())
wd, _ := os.Getwd()
tests := []struct {
value interface{}
store map[string]interface{}
want interface{}
error bool
}{
{1, nil, 1, false},
{[]string{"1"}, nil, []string{"1"}, false},
{"string", nil, "string", false},
{"json://testdata/vars.json", nil, map[string]interface{}{"foo": "test", "bar": float64(1)}, false},
{"json://not_exists.json", nil, "json://not_exists.json", true},
{"json://" + brokenJson.Name(), nil, "json://" + brokenJson.Name(), true},
{
"json://testdata/non_template.json",
map[string]interface{}{"vars": map[string]interface{}{"foo": "test", "bar": 1}},
map[string]interface{}{"foo": "{{.vars.foo -}}", "bar": float64(1)},
false,
},
{
"json://testdata/template.json.template",
map[string]interface{}{"vars": map[string]interface{}{"foo": "test", "bar": 1}},
map[string]interface{}{"foo": "test", "bar": float64(1)},
false,
},
}
for _, tt := range tests {
got, err := evaluateSchema(tt.value, wd, tt.store)
if diff := cmp.Diff(got, tt.want, nil); diff != "" {
t.Errorf("%s", diff)
}
if (tt.error && err == nil) || (!tt.error && err != nil) {
t.Errorf("no much error")
}
}
}