-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathconfiguration_test.go
More file actions
237 lines (210 loc) · 8.02 KB
/
configuration_test.go
File metadata and controls
237 lines (210 loc) · 8.02 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package configuration_test
import (
. "github.com/AliceO2Group/Control/configuration"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v2"
)
var _ = Describe("Configuration", func() {
var (
c Configuration
err error
)
DoConfigurationTests := func() {
var (
o2_control_tasks_1_map = Map{
"name": String("fairmq-ex-1-n-1-sampler"),
"control": Map{
"mode": String("fairmq"),
},
"wants": Map{
"cpu": String("1"),
"memory": String("256"),
"ports": String("1"),
},
"bind": Array{
Map{
"name": String("data1"),
"type": String("push"),
"sndBufSize": String("1000"),
"rcvBufSize": String("1000"),
"rateLogging": String("0"),
},
},
"properties": Map{
"severity": String("trace"),
"color": String("false"),
},
"command": Map{
"env": Array{},
"shell": String("true"),
"arguments": Array{},
"value": String("fairmq-ex-1-n-1-sampler"),
},
}
recursivePutMap = Map{
"firstKey": String("one"),
"secondKey": Array{
Map{
"name": String("first"),
"type": String("an array item"),
},
Map{
"name": String("second"),
"type": String("an array item"),
},
Map{
"name": String("third"),
"type": String("and yet another array item"),
},
},
"thirdKey": Map{
"just some": String("stuff"),
},
}
recursivePutArray = Array{
Map{
"name": String("first"),
"type": String("an array item with a property map inside"),
"properties": Map{
"just some": String("stuff"),
},
},
Map{
"name": String("second"),
"type": String("an array item"),
},
Map{
"name": String("third"),
"type": String("and yet another array item"),
},
}
recursivePutString = String("this is a bit underwhelming compared to the other two...")
)
It("should return no error when creating an instance", func() {
Expect(err).NotTo(HaveOccurred())
})
Context("to get a subtree or value", func() {
It("should correctly get a single item", func() {
Expect(c.Get("o2/control/globals/o2_install_path")).To(Equal("/opt/alisw/el7"))
Expect(c.Get("o2/control/tasks[1]/name")).To(Equal("fairmq-ex-1-n-1-sampler"))
Expect(c.Get("o2/control/globals/control/direct/control_port_args[1]")).To(Equal("{{ controlPort }}"))
})
It("should correctly recursively get a configuration subtree", func() {
Expect(c.GetRecursive("o2/control/tasks[1]")).To(Equal(o2_control_tasks_1_map))
})
It("should correctly recursively get a configuration subtree as YAML", func() {
marshalled, marshErr := yaml.Marshal(o2_control_tasks_1_map)
Expect(marshErr).NotTo(HaveOccurred())
Expect(c.GetRecursiveYaml("o2/control/tasks[1]")).To(Equal(marshalled))
})
})
Context("to check the existence of a key", func() {
It("should correctly determine whether a value node is defined", func() {
Expect(c.Exists("o2/control/workflows[0]/role/roles[1]/name")).To(BeTrue())
Expect(c.Exists("o2/control/workflows[0]/role/roles[4]/name")).To(BeFalse())
})
It("should correctly determine whether a map node is defined", func() {
Expect(c.Exists("o2")).To(BeTrue())
})
It("should correctly determine whether an array node is defined", func() {
Expect(c.Exists("o2/control/globals/control/direct/control_port_args[1]")).To(BeTrue())
Expect(c.Exists("o2/control/globals/control/direct/control_port_args")).To(BeTrue())
})
It("should correctly address non-existent keys", func() {
Expect(c.Exists("")).To(BeFalse())
Expect(c.Exists("FakeKey")).To(BeFalse())
})
})
Context("to add a new subtree or value", func(){
It("should correctly push a single value", func() {
Expect(c.Exists("o2/control/tasks[0]/bind[1]/newSingleValue")).To(BeFalse())
putErr := c.Put("o2/control/tasks[0]/bind[1]/newSingleValue", "foobar")
Expect(putErr).NotTo(HaveOccurred())
Expect(c.Get("o2/control/tasks[0]/bind[1]/newSingleValue")).To(Equal("foobar"))
})
It("should correctly push a configuration.Map", func() {
Expect(c.Exists("o2/control/tasks[0]/bind[1]/newMap")).To(BeFalse())
putErr := c.PutRecursive("o2/control/tasks[0]/bind[1]/newMap", recursivePutMap)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursive("o2/control/tasks[0]/bind[1]/newMap")).To(Equal(recursivePutMap))
})
It("should correctly push an configuration.Array", func() {
Expect(c.Exists("o2/control/tasks[0]/bind[1]/newArray")).To(BeFalse())
putErr := c.PutRecursive("o2/control/tasks[0]/bind[1]/newArray", recursivePutArray)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursive("o2/control/tasks[0]/bind[1]/newArray")).To(Equal(recursivePutArray))
})
It("should correctly push a configuration.String", func() {
Expect(c.Exists("o2/control/tasks[0]/bind[1]/newString")).To(BeFalse())
putErr := c.PutRecursive("o2/control/tasks[0]/bind[1]/newString", recursivePutString)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursive("o2/control/tasks[0]/bind[1]/newString")).To(BeEquivalentTo(recursivePutString))
})
It("should correctly push a YAML map", func() {
Expect(c.Exists("o2/control/tasks[0]/bind[1]/newYamlMap")).To(BeFalse())
marshalled, marshErr := yaml.Marshal(recursivePutMap)
Expect(marshErr).NotTo(HaveOccurred())
putErr := c.PutRecursiveYaml("o2/control/tasks[0]/bind[1]/newYamlMap", marshalled)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursiveYaml("o2/control/tasks[0]/bind[1]/newYamlMap")).To(Equal(marshalled))
})
It("should correctly push a YAML array", func() {
Expect(c.Exists("o2/control/tasks[0]/bind[1]/newYamlArray")).To(BeFalse())
marshalled, marshErr := yaml.Marshal(recursivePutArray)
Expect(marshErr).NotTo(HaveOccurred())
putErr := c.PutRecursiveYaml("o2/control/tasks[0]/bind[1]/newYamlArray", marshalled)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursiveYaml("o2/control/tasks[0]/bind[1]/newYamlArray")).To(Equal(marshalled))
})
})
Context("to replace/update an existing subtree or value", func() {
It("should correctly push a single value", func() {
Expect(c.Exists("o2/control/globals/config_basedir")).To(BeTrue())
putErr := c.Put("o2/control/globals/config_basedir", "foobar")
Expect(putErr).NotTo(HaveOccurred())
Expect(c.Get("o2/control/globals/config_basedir")).To(Equal("foobar"))
})
It("should correctly push a configuration.Map", func() {
Expect(c.Exists("o2/control/tasks[0]/bind[1]")).To(BeTrue())
putErr := c.PutRecursive("o2/control/tasks[0]/bind[1]", recursivePutMap)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursive("o2/control/tasks[0]/bind[1]")).To(Equal(recursivePutMap))
})
It("should correctly push an configuration.Array", func() {
Expect(c.Exists("o2/control/tasks[0]/wants")).To(BeTrue())
putErr := c.PutRecursive("o2/control/tasks[0]/wants", recursivePutArray)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursive("o2/control/tasks[0]/wants")).To(Equal(recursivePutArray))
})
It("should correctly push a configuration.String", func() {
Expect(c.Exists("o2/control/tasks[0]/wants")).To(BeTrue())
putErr := c.PutRecursive("o2/control/tasks[0]/wants", recursivePutString)
Expect(putErr).NotTo(HaveOccurred())
Expect(c.GetRecursive("o2/control/tasks[0]/wants")).To(BeEquivalentTo(recursivePutString))
})
})
}
Describe("when interacting with an instance", func() {
Context("with Consul backend", func() {
BeforeEach(func() {
c, err = NewConfiguration("consul://dummy")
})
It("should be of type *ConsulConfiguration", func() {
_, ok := c.(*ConsulConfiguration)
Expect(ok).To(Equal(true))
})
//DoConfigurationTests()
})
Context("with YAML file backend", func() {
BeforeEach(func() {
c, err = NewConfiguration("file://" + *tmpDir + "/" + configFile)
})
It("should be of type *YamlConfiguration", func() {
_, ok := c.(*YamlConfiguration)
Expect(ok).To(Equal(true))
})
DoConfigurationTests()
})
})
})