-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_test.go
58 lines (53 loc) · 1.07 KB
/
build_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
package casper
import (
"bytes"
"fmt"
"testing"
"github.com/miracl/casper/source"
)
func TestBuild(t *testing.T) {
testCases := []struct {
tmpl string
source source.Getter
res string
}{
{
`{"cfg1": "{{.key1}}", "cfg2": "{{.key2}}"}`,
source.NewSource(map[string]interface{}{
"key1": "var1",
"key2": "var2",
}),
`{"cfg1": "var1", "cfg2": "var2"}`,
},
{
`{"cfg1": "{{.key1}}", "cfg2": "{{if .key2}}{{.key2}}{{end}}", "cfg3": "{{.key3}}"}`,
source.NewSource(map[string]interface{}{
"key1": "var1",
}),
`{"cfg1": "var1", "cfg2": "", "cfg3": "<no value>"}`,
},
{
``,
source.NewSource(map[string]interface{}{
"key1": "var1",
}),
``,
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("Case%v", i), func(t *testing.T) {
// build
config, err := BuildConfig{
Template: bytes.NewBufferString(tc.tmpl),
Source: tc.source,
}.Build()
if err != nil {
t.Fatal(err)
}
// compare
if string(config) != tc.res {
t.Errorf("Got %v; want %v", string(config), tc.res)
}
})
}
}