-
Notifications
You must be signed in to change notification settings - Fork 0
/
masks_test.go
108 lines (104 loc) · 3.34 KB
/
masks_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
package boom
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/smallfish/simpleyaml"
)
var _ = Describe("Boom", func() {
var (
boom *Boom
)
Context("Mask", func() {
BeforeEach(func() {
boom = New(completeManifestPath, false)
})
It("clears all but the given list in root", func() {
err := boom.Mask("jobs", "instances")
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
manifest, err := result.Map()
Expect(err).NotTo(HaveOccurred())
Expect(len(manifest)).To(Equal(1))
Expect(manifest["jobs"]).ToNot(BeNil())
})
Context("when the list doesn't exist", func() {
It("returns an error", func() {
err := boom.Mask("not-existing", "instances")
Expect(err).To(MatchError("list `not-existing` not found"))
})
})
Context("when the list specified isn't a list", func() {
It("returns an error", func() {
err := boom.Mask("properties", "instances")
Expect(err).To(MatchError("key `properties` is not a list"))
})
})
Context("when the key doesn't exist", func() {
It("does return empty values", func() {
err := boom.Mask("jobs", "not-existing-key")
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
job := result.Get("jobs").GetIndex(0)
Expect(job).NotTo(BeNil())
jobMap, err := job.Map()
Expect(err).NotTo(HaveOccurred())
Expect(len(jobMap)).To(Equal(2))
Expect(job.Get("not-existing-key")).NotTo(BeNil())
})
})
Context("when only the list is specified", func() {
It("clears all but name", func() {
err := boom.Mask("jobs", "")
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
job := result.Get("jobs").GetIndex(0)
Expect(job).NotTo(BeNil())
jobMap, err := job.Map()
Expect(err).NotTo(HaveOccurred())
Expect(len(jobMap)).To(Equal(1))
})
})
Context("Instances", func() {
It("clears all but name and instances", func() {
err := boom.Mask("jobs", "instances")
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
job := result.Get("jobs").GetIndex(0)
Expect(job).NotTo(BeNil())
jobMap, err := job.Map()
Expect(err).NotTo(HaveOccurred())
Expect(len(jobMap)).To(Equal(2))
})
})
Context("Instances", func() {
It("clears all but name and instances", func() {
err := boom.Mask("jobs", "instances")
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
job := result.Get("jobs").GetIndex(0)
Expect(job).NotTo(BeNil())
jobMap, err := job.Map()
Expect(err).NotTo(HaveOccurred())
Expect(len(jobMap)).To(Equal(2))
})
})
Context("Versions", func() {
It("clears all but name and version", func() {
err := boom.Mask("releases", "version")
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
job := result.Get("releases").GetIndex(0)
Expect(job).NotTo(BeNil())
jobMap, err := job.Map()
Expect(err).NotTo(HaveOccurred())
Expect(len(jobMap)).To(Equal(2))
})
})
})
})