-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot_test.go
73 lines (64 loc) · 1.41 KB
/
root_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
package cmd
import (
"bytes"
"io"
"io/ioutil"
"os"
"strings"
"testing"
"github.com/airfocusio/go-template/pkg"
"github.com/stretchr/testify/assert"
)
func TestRun(t *testing.T) {
input := "Hello, {{ .Val.message }}!"
inputReader := strings.NewReader(input)
var outputBytes bytes.Buffer
outputWriter := io.Writer(&outputBytes)
err := Run(inputReader, outputWriter, pkg.RenderData{
Val: map[string]interface{}{
"message": "World",
},
})
assert.NoError(t, err)
output := outputBytes.String()
assert.Equal(t, "Hello, World!", output)
}
func TestBuildRenderData(t *testing.T) {
valueFlags := arrayFlags{"some=thing"}
valueFile, err := ioutil.TempFile(os.TempDir(), "go-template-*.yaml")
assert.NoError(t, err)
defer os.Remove(valueFile.Name())
err = ioutil.WriteFile(valueFile.Name(), []byte(`
persons:
- name: Adam
age: 42
- name: Eve
age: 41
apple: pie
`), 0o664)
assert.NoError(t, err)
valueFileFlags := arrayFlags{valueFile.Name()}
os.Clearenv()
os.Setenv("FOO", "BAR")
data, err := BuildRenderData(valueFlags, valueFileFlags)
assert.NoError(t, err)
assert.Equal(t, pkg.RenderData{
Val: map[string]interface{}{
"some": "thing",
"persons": []interface{}{
map[string]interface{}{
"name": "Adam",
"age": 42,
},
map[string]interface{}{
"name": "Eve",
"age": 41,
},
},
"apple": "pie",
},
Env: map[string]string{
"FOO": "BAR",
},
}, *data)
}