forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
113 lines (98 loc) · 3.16 KB
/
main_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
package main_test
import (
"os"
"os/exec"
"path/filepath"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("Main", func() {
var pathToExecutable string
fixturePath := func(name string) string {
wd, _ := os.Getwd()
return filepath.Join(wd, "fixtures", name)
}
BeforeEach(func() {
var err error
pathToExecutable, err = gexec.Build("github.com/akshaymankar/int-yaml")
Expect(err).ShouldNot(HaveOccurred())
})
AfterEach(func() {
gexec.CleanupBuildArtifacts()
})
Describe("Basics", func() {
It("should exit with 0 exit code", func() {
testFile := fixturePath("test.yml")
command := exec.Command(pathToExecutable, testFile)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
})
It("should print the yaml contents", func() {
testFile := fixturePath("test.yml")
command := exec.Command(pathToExecutable, testFile)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session.Out).Should(gbytes.Say("is_this_test: true"))
})
})
Describe("Interpolation", func() {
It("should interpolate with all options", func() {
testFile := fixturePath("interpolate.yml")
_ = os.Setenv("ENVVAR_InEnv", "Magical")
command := exec.Command(pathToExecutable, testFile,
"--vars-file", fixturePath("vars-file.yml"),
"--var-file", "getThisFromVarFile="+fixturePath("var-file.txt"),
"--vars-env", "ENVVAR",
"--var=getThisFromVar='Got it from var'")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
//If you edit this, remember to convert tabs to spaces
expectedOutput := `examples:
cli-vars:
foo: Got it from var
env-vars:
foo: Magical
var-file:
foo: |
Tressure of the var-file
vars-file:
bar: Map simple entry
baz:
- first element
- second element
foo: Simple entry`
Eventually(session.Out).Should(gbytes.Say(expectedOutput))
})
})
Describe("Patching", func() {
It("should interpolate with all options", func() {
testFile := fixturePath("patch.yml")
command := exec.Command(pathToExecutable, testFile, "--ops-file", fixturePath("ops-file.yml"))
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
//If you edit this, remember to convert tabs to spaces
expectedOutput := `movie: Rang de basanti
songs:
- Khalbali
- Paathshala
- Tu bin bataye
- Luka chuppi`
Eventually(session.Out).Should(gbytes.Say(expectedOutput))
})
})
Describe("Querying", func() {
It("should get value of given path", func() {
testFile := fixturePath("patch.yml")
command := exec.Command(pathToExecutable, testFile, "--path", "/movie")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Eventually(session.Out).Should(gbytes.Say("^Rang de basanti\n$"))
})
})
})