forked from mandelsoft/spiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spiff_test.go
148 lines (118 loc) · 4.3 KB
/
spiff_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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"io/ioutil"
"os"
"os/exec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("Running spiff", func() {
Context("merge", func() {
var merge *Session
Context("when given a bad file path", func() {
BeforeEach(func() {
var err error
merge, err = Start(exec.Command(spiff, "merge", "foo.yml"), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
})
It("says file not found", func() {
Expect(merge.Wait()).To(Exit(1))
Expect(merge.Err).To(Say("foo.yml: no such file or directory"))
})
})
Context("when given a single file", func() {
var basicTemplate *os.File
BeforeEach(func() {
var err error
basicTemplate, err = ioutil.TempFile(os.TempDir(), "basic.yml")
Expect(err).NotTo(HaveOccurred())
basicTemplate.Write([]byte(`
---
foo: bar
`))
merge, err = Start(exec.Command(spiff, "merge", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
os.Remove(basicTemplate.Name())
})
It("resolves the template and prints it out", func() {
Expect(merge.Wait()).To(Exit(0))
Expect(merge.Out).To(Say(`foo: bar`))
})
})
Context("when given values", func() {
var basicTemplate *os.File
BeforeEach(func() {
var err error
basicTemplate, err = ioutil.TempFile(os.TempDir(), "basic.yml")
Expect(err).NotTo(HaveOccurred())
basicTemplate.Write([]byte(`
---
foo: (( values ))
`))
})
AfterEach(func() {
os.Remove(basicTemplate.Name())
})
It("resolves the template with flat definition", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues=X", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(0))
Expect(merge.Out).To(Say(`foo: X`))
})
It("resolves the template with deep definition", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues.alice=X", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(0))
Expect(merge.Out).To(Say(`foo:
alice: X`))
})
It("resolves the template with multiple deep definitions", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues.alice=X", "-Dvalues.bob=Z", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(0))
Expect(merge.Out).To(Say(`foo:
alice: X
bob: Z`))
})
It("resolves the template with escaped deep definitions", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues.alice\\.bob=X", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(0))
Expect(merge.Out).To(Say(`foo:
alice.bob: X`))
})
It("resolves the template with escaped dot at end", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues.alice\\..bob=X", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(0))
Expect(merge.Out).To(Say(`foo:
alice.:
bob: X`))
})
It("resolves the template with escaped \\ deep definitions", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues.alice\\\\.bob=X", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(0))
Expect(merge.Out).To(Say(`foo:
alice\\:
bob: X`))
})
It("fails for inconsistent definitions", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues=X", "-Dvalues.alice=X", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(1))
Expect(merge.Err).To(Say(`.*error in value definitions \(-D\): field "values" in values.alice is no map`))
})
It("fails for invalid definitions", func() {
merge, err := Start(exec.Command(spiff, "merge", "-Dvalues..alice=X", basicTemplate.Name()), GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Expect(merge.Wait()).To(Exit(1))
Expect(merge.Err).To(Say(`.*error in value definitions \(-D\): empty path component in "values..alice"`))
})
})
})
})