-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathservice_test.go
More file actions
659 lines (630 loc) · 24.3 KB
/
service_test.go
File metadata and controls
659 lines (630 loc) · 24.3 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
package local
import (
apricotpb "github.com/AliceO2Group/Control/apricot/protos"
"github.com/AliceO2Group/Control/configuration/cfgbackend"
"github.com/AliceO2Group/Control/configuration/componentcfg"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
// TODO:
// - with little effort this could be generalized to test also cacheproxy.service
// - with some more effort, we should also test the same with consul backend, since we break the abstraction layer
// in a few functions in service.go
var _ = Describe("local service", func() {
var (
svc *Service
err error
)
Context("with YAML file backend", func() {
BeforeEach(func() {
svc, err = NewService("file://" + *tmpDir + "/" + serviceConfigFile)
Expect(err).NotTo(HaveOccurred())
})
It("should be of type *YamlSource", func() {
_, ok := svc.src.(*cfgbackend.YamlSource)
Expect(ok).To(Equal(true))
})
Describe("creating a new run number", func() {
When("the run number does not exist yet", func() {
It("should return number 1", func() {
Expect(svc.NewRunNumber()).To(Equal(uint32(1)))
})
It("should return number 2 after number 1", func() {
Expect(svc.NewRunNumber()).To(Equal(uint32(2)))
})
})
})
Describe("getting defaults", func() {
var defaults map[string]string
BeforeEach(func() {
defaults = svc.GetDefaults()
})
When("the defaults are retrieved", func() {
It("should contain the elements from the test YAML file at o2/runtime/aliecs/defaults", func() {
Expect(defaults).To(HaveKeyWithValue("key1", "value1"))
})
It("should contain some prefilled key-values regardless of the information in the configuration backend", func() {
Expect(defaults).To(HaveKey("core_hostname"))
})
})
})
Describe("getting vars", func() {
var vars map[string]string
BeforeEach(func() {
vars = svc.GetVars()
})
When("the vars are retrieved", func() {
It("should contain the elements from the test YAML file at o2/runtime/aliecs/vars", func() {
Expect(vars).To(HaveKeyWithValue("key2", "value2"))
})
})
})
Describe("getting the list of detectors", func() {
var detectors []string
When("the full detector list is retrieved (incl. detector-like subsystems)", func() {
BeforeEach(func() {
detectors, err = svc.ListDetectors(true)
})
It("should contain the detectors in the test YAML file at o2/hardware/detectors", func() {
Expect(err).NotTo(HaveOccurred())
Expect(detectors).To(ContainElements("ABC", "DEF", "TRG", "XYZ"))
})
})
When("the pure detector list is retrieved", func() {
BeforeEach(func() {
detectors, err = svc.ListDetectors(false)
})
It("should contain the detectors in the test YAML file at o2/hardware/detectors", func() {
Expect(err).NotTo(HaveOccurred())
Expect(detectors).To(ContainElements("ABC", "DEF", "XYZ"))
})
})
})
Describe("getting the list of hosts", func() {
var hosts []string
When("the list of hosts is retrieved for all detectors", func() {
BeforeEach(func() {
hosts, err = svc.GetHostInventory("")
})
It("should contain all the hosts for all the detectors in the test YAML file at o2/hardware/detectors", func() {
Expect(err).NotTo(HaveOccurred())
Expect(hosts).To(ContainElements("flp001", "flp002", "flp003", "flp100"))
})
})
When("the list of hosts is retrieved for a valid detector", func() {
BeforeEach(func() {
hosts, err = svc.GetHostInventory("ABC")
})
It("should contain all the hosts for the ABC detector in the test YAML file at o2/hardware/detectors", func() {
Expect(err).NotTo(HaveOccurred())
Expect(hosts).To(ContainElements("flp001"))
})
})
When("the list of hosts is retrieved for a non-existent detector", func() {
BeforeEach(func() {
hosts, err = svc.GetHostInventory("NOPE")
})
It("should produce an error", func() {
Expect(err).To(HaveOccurred())
})
})
When("the list of hosts is retrieved for an existing detector with no FLPs assigned", func() {
BeforeEach(func() {
hosts, err = svc.GetHostInventory("XYZ")
})
It("should return an empty list", func() {
Expect(err).NotTo(HaveOccurred())
Expect(hosts).To(BeEmpty())
})
})
})
Describe("getting the detectors FLP inventory", func() {
var inventory map[string][]string
When("the inventory is retrieved", func() {
BeforeEach(func() {
inventory, err = svc.GetDetectorsInventory()
})
It("should contain all the hosts for all the detectors in the test YAML file at o2/hardware/detectors", func() {
Expect(err).NotTo(HaveOccurred())
Expect(inventory).To(HaveKey("ABC"))
Expect(inventory["ABC"]).To(ContainElements("flp001"))
Expect(inventory).To(HaveKey("DEF"))
Expect(inventory["DEF"]).To(ContainElements("flp002", "flp003"))
Expect(inventory).To(HaveKey("TRG"))
Expect(inventory["TRG"]).To(ContainElements("flp100"))
Expect(inventory).To(HaveKey("XYZ"))
Expect(inventory["XYZ"]).To(BeEmpty())
})
})
})
Describe("getting component configuration", func() {
var (
payload string
query *componentcfg.Query
err error
)
When("requesting an entry for a concrete run type and a concrete role", func() {
It("should return the payload for the concrete run type and role", func() {
query, err = componentcfg.NewQuery("qc/PHYSICS/role1/entry1")
Expect(err).NotTo(HaveOccurred())
payload, err = svc.GetComponentConfiguration(query)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("entry1 config PHYSICS role1"))
})
})
When("requesting an entry for ANY run type and any role", func() {
It("should return the payload for ANY/any", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry1")
Expect(err).NotTo(HaveOccurred())
payload, err = svc.GetComponentConfiguration(query)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("entry1 config ANY any"))
})
})
When("requesting an entry in a subfolder", func() {
It("should return the expected payload", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/sub/entry12")
Expect(err).NotTo(HaveOccurred())
payload, err = svc.GetComponentConfiguration(query)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("world"))
})
})
})
Describe("getting component configuration with last index", func() {
var (
query *componentcfg.Query
err error
)
When("a payload is retrieved", func() {
It("should return an error, because file backend does not support last index", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry1")
Expect(err).NotTo(HaveOccurred())
_, _, err = svc.GetComponentConfigurationWithLastIndex(query)
Expect(err).To(HaveOccurred())
})
})
})
Describe("getting and processing component configuration", func() {
var (
payload string
query *componentcfg.Query
err error
)
When("requesting an entry which requires including another entry and inserting a variable", func() {
It("should return the processed payload", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry10")
Expect(err).NotTo(HaveOccurred())
varStack := make(map[string]string)
varStack["var1"] = "hello"
payload, err = svc.GetAndProcessComponentConfiguration(query, varStack)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("hello world"))
})
})
When("requesting an entry which requires including another entry in a different node", func() {
It("should return the processed payload", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry12")
Expect(err).NotTo(HaveOccurred())
varStack := make(map[string]string)
payload, err = svc.GetAndProcessComponentConfiguration(query, varStack)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("hello world"))
})
})
When("requesting an entry which is in a subfolder", func() {
It("should return the processed payload", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/sub/entry12")
Expect(err).NotTo(HaveOccurred())
varStack := make(map[string]string)
payload, err = svc.GetAndProcessComponentConfiguration(query, varStack)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("world"))
})
})
})
Describe("resolving a query", func() {
var (
query *componentcfg.Query
resolved *componentcfg.Query
err error
)
When("resolving an ANY/any query which may match an ANY/any and a concrete one in the configuration tree", func() {
It("should resolve to ANY/any query", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry1")
Expect(err).NotTo(HaveOccurred())
resolved, err = svc.ResolveComponentQuery(query)
Expect(err).NotTo(HaveOccurred())
Expect(resolved.RunType).To(Equal(apricotpb.RunType_ANY))
Expect(resolved.RoleName).To(Equal("any"))
})
})
When("resolving an ANY/any query while there is only PHYSICS/role1 entry in the configuration tree", func() {
It("should fail to resolve", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry2")
Expect(err).NotTo(HaveOccurred())
_, err = svc.ResolveComponentQuery(query)
Expect(err).To(HaveOccurred())
})
})
When("resolving a concrete PHYSICS/role1 query which may match an ANY/any and that concrete one in the configuration tree", func() {
It("should resolve to PHYSICS/role1 query", func() {
query, err = componentcfg.NewQuery("qc/PHYSICS/role1/entry1")
Expect(err).NotTo(HaveOccurred())
resolved, err = svc.ResolveComponentQuery(query)
Expect(err).NotTo(HaveOccurred())
Expect(resolved.RunType).To(Equal(apricotpb.RunType_PHYSICS))
Expect(resolved.RoleName).To(Equal("role1"))
})
})
When("resolving a concrete PHYSICS/role1 query while there is ANY/any entry in the configuration tree", func() {
It("should resolve to ANY/any query", func() {
query, err = componentcfg.NewQuery("qc/PHYSICS/role1/entry11")
Expect(err).NotTo(HaveOccurred())
resolved, err = svc.ResolveComponentQuery(query)
Expect(err).NotTo(HaveOccurred())
Expect(resolved.RunType).To(Equal(apricotpb.RunType_ANY))
Expect(resolved.RoleName).To(Equal("any"))
})
})
When("resolving a query to an entry in a subfolder", func() {
It("should resolve it correctly", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/sub/entry12")
Expect(err).NotTo(HaveOccurred())
resolved, err = svc.ResolveComponentQuery(query)
Expect(err).NotTo(HaveOccurred())
Expect(resolved.RunType).To(Equal(apricotpb.RunType_ANY))
Expect(resolved.RoleName).To(Equal("any"))
Expect(resolved.EntryKey).To(Equal("sub/entry12"))
})
})
})
Describe("getting raw json payload of everything under a node", func() {
var (
payload string
err error
)
When("retrieving a raw json payload", func() {
It("should return a json with correct content and formatting", func() {
payload, err = svc.RawGetRecursive("o2/components/qc/TECHNICAL")
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("{\n\t\"any\": {\n\t\t\"entry\": \"config\"\n\t}\n}"))
})
})
})
Describe("importing component configuration", func() {
var (
importedPayload string
retrievedPayload string
existingComponentUpdated bool
existingEntryUpdated bool
query *componentcfg.Query
err error
)
When("we import a new configuration payload for a new component", func() {
It("should be correctly stored", func() {
query, err = componentcfg.NewQuery("reco/ANY/any/entry2")
Expect(err).NotTo(HaveOccurred())
importedPayload = "hello"
existingComponentUpdated, existingEntryUpdated, err = svc.ImportComponentConfiguration(query, importedPayload, true)
Expect(err).NotTo(HaveOccurred())
Expect(existingComponentUpdated).To(BeFalse())
Expect(existingEntryUpdated).To(BeFalse())
retrievedPayload, err = svc.GetComponentConfiguration(query)
Expect(err).NotTo(HaveOccurred())
Expect(retrievedPayload).To(Equal(importedPayload))
})
})
When("we import a new configuration payload for a new component, but we do not set the newComponent flag", func() {
It("should produce an error", func() {
query, err = componentcfg.NewQuery("gpu/ANY/any/entry2")
Expect(err).NotTo(HaveOccurred())
importedPayload = "hello"
existingComponentUpdated, existingEntryUpdated, err = svc.ImportComponentConfiguration(query, importedPayload, false)
Expect(err).To(HaveOccurred())
})
})
When("we import a new configuration entry for an existing component", func() {
It("should be correctly stored", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry3")
Expect(err).NotTo(HaveOccurred())
importedPayload = "hello"
existingComponentUpdated, existingEntryUpdated, err = svc.ImportComponentConfiguration(query, importedPayload, false)
Expect(err).NotTo(HaveOccurred())
Expect(existingComponentUpdated).To(BeTrue())
Expect(existingEntryUpdated).To(BeFalse())
retrievedPayload, err = svc.GetComponentConfiguration(query)
Expect(err).NotTo(HaveOccurred())
Expect(retrievedPayload).To(Equal(importedPayload))
})
})
When("we import a new payload to an existing entry for an existing component", func() {
It("should be correctly stored", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry4")
Expect(err).NotTo(HaveOccurred())
importedPayload = "hello"
existingComponentUpdated, existingEntryUpdated, err = svc.ImportComponentConfiguration(query, importedPayload, false)
Expect(err).NotTo(HaveOccurred())
importedPayload = "hello2"
existingComponentUpdated, existingEntryUpdated, err = svc.ImportComponentConfiguration(query, importedPayload, false)
Expect(err).NotTo(HaveOccurred())
Expect(existingComponentUpdated).To(BeTrue())
Expect(existingEntryUpdated).To(BeTrue())
retrievedPayload, err = svc.GetComponentConfiguration(query)
Expect(err).NotTo(HaveOccurred())
Expect(retrievedPayload).To(Equal(importedPayload))
})
})
When("we import a new payload to a new entry which should go to a non-existing subfolder", func() {
It("should be correctly stored", func() {
query, err = componentcfg.NewQuery("qc/PHYSICS/role1/sub/entry2")
Expect(err).NotTo(HaveOccurred())
importedPayload = "sub hello"
existingComponentUpdated, existingEntryUpdated, err = svc.ImportComponentConfiguration(query, importedPayload, false)
Expect(err).NotTo(HaveOccurred())
Expect(svc.src.Exists("o2/components/qc/PHYSICS/role1/sub/entry2")).To(BeTrue())
retrievedPayload, err = svc.GetComponentConfiguration(query)
Expect(err).NotTo(HaveOccurred())
Expect(retrievedPayload).To(Equal(importedPayload))
})
})
})
Describe("getting detector for host", func() {
var (
detector string
err error
)
When("retrieving the detector for a host", func() {
It("should return the correct detector", func() {
detector, err = svc.GetDetectorForHost("flp001")
Expect(err).NotTo(HaveOccurred())
Expect(detector).To(Equal("ABC"))
})
})
When("retrieving the detector for a non-existing host", func() {
It("should produce an error", func() {
detector, err = svc.GetDetectorForHost("NOPE")
Expect(err).To(HaveOccurred())
})
})
When("retrieving the detector spelled lower-case for a host", func() {
// not supported
It("should produce an error", func() {
detector, err = svc.GetDetectorForHost("abc")
Expect(err).To(HaveOccurred())
})
})
})
Describe("getting detectors for hosts", func() {
var (
detectors []string
err error
)
When("retrieving the detectors for a list of hosts", func() {
It("should return the correct detectors", func() {
detectors, err = svc.GetDetectorsForHosts([]string{"flp001", "flp002"})
Expect(err).NotTo(HaveOccurred())
Expect(detectors).To(ContainElements("ABC", "DEF"))
})
})
When("retrieving the detectors for a non-existing host", func() {
It("should produce an error", func() {
detectors, err = svc.GetDetectorsForHosts([]string{"NOPE"})
Expect(err).To(HaveOccurred())
})
})
When("retrieving the detectors for a list of hosts with a non-existing host", func() {
It("should produce an error", func() {
detectors, err = svc.GetDetectorsForHosts([]string{"flp001", "NOPE"})
Expect(err).To(HaveOccurred())
})
})
})
Describe("getting CRU cards for a host", func() {
var (
cards []string
err error
)
When("retrieving the CRU cards for a host", func() {
It("should return the correct CRU cards", func() {
cards, err = svc.GetCRUCardsForHost("flp001")
Expect(err).NotTo(HaveOccurred())
Expect(cards).To(ContainElements("0228", "0229"))
})
})
When("retrieving the CRU cards for a non-existing host", func() {
It("should produce an error", func() {
cards, err = svc.GetCRUCardsForHost("NOPE")
Expect(err).To(HaveOccurred())
})
})
When("retrieving the CRU cards for an FLP with invalid \"cards\" JSON", func() {
It("should produce an error", func() {
cards, err = svc.GetCRUCardsForHost("flp500")
Expect(err).To(HaveOccurred())
})
})
})
Describe("getting endpoints for a CRU card", func() {
var (
endpoints []string
err error
)
When("retrieving the endpoints for a CRU card", func() {
It("should return the correct endpoints", func() {
endpoints, err = svc.GetEndpointsForCRUCard("flp001", "0228")
Expect(err).NotTo(HaveOccurred())
Expect(endpoints).To(ContainElements("0", "1"))
})
})
When("retrieving the endpoints for a non-existing host", func() {
It("should produce an error", func() {
endpoints, err = svc.GetEndpointsForCRUCard("NOPE", "0228")
Expect(err).To(HaveOccurred())
})
})
When("retrieving the endpoints for a non-existing CRU card", func() {
// fixme: probably incorrect behaviour, but I don't want to risk breaking something
It("should not return an empty slice", func() {
endpoints, err = svc.GetEndpointsForCRUCard("flp001", "NOPE")
Expect(endpoints).To(BeEmpty())
Expect(err).NotTo(HaveOccurred())
})
})
})
Describe("getting link IDs for a CRU card endpoint", func() {
var (
linkIDs []string
err error
)
When("retrieving the link IDs for a CRU card endpoint", func() {
It("should return the correct link IDs", func() {
linkIDs, err = svc.GetLinkIDsForCRUEndpoint("flp001", "0228", "0", false)
Expect(err).NotTo(HaveOccurred())
Expect(linkIDs).To(ContainElements("0", "1", "2", "10"))
})
It("should return the correct enabled link IDs", func() {
linkIDs, err = svc.GetLinkIDsForCRUEndpoint("flp001", "0228", "0", true)
Expect(err).NotTo(HaveOccurred())
Expect(linkIDs).To(ContainElements("0", "2"))
})
})
When("retrieving the link IDs for a non-existing host", func() {
It("should produce an error", func() {
linkIDs, err = svc.GetLinkIDsForCRUEndpoint("NOPE", "0228", "0", true)
Expect(err).To(HaveOccurred())
})
})
When("retrieving the link IDs for a non-existing CRU card", func() {
It("should produce an error", func() {
linkIDs, err = svc.GetLinkIDsForCRUEndpoint("flp001", "NOPE", "0", true)
Expect(err).To(HaveOccurred())
})
})
When("retrieving the link IDs for a non-existing endpoint", func() {
It("should produce an error", func() {
linkIDs, err = svc.GetLinkIDsForCRUEndpoint("flp001", "0228", "NOPE", true)
Expect(err).To(HaveOccurred())
})
})
When("trying to retrieve the link IDs for an FLP belonging to a CRORC detector", func() {
It("should produce an error", func() {
linkIDs, err = svc.GetLinkIDsForCRUEndpoint("flp146", "0110", "0", true)
Expect(err).To(HaveOccurred())
})
})
})
Describe("getting aliased link IDs for a detector", func() {
var (
linkIDs []string
err error
)
When("retrieving the link IDs for a detector", func() {
It("should return the correct link IDs", func() {
linkIDs, err = svc.GetAliasedLinkIDsForDetector("ABC", false)
Expect(err).NotTo(HaveOccurred())
Expect(linkIDs).To(Equal([]string{"01", "123", "400", "58", "59", "600", "62", "63", "a-b_c=d", "string"}))
})
})
When("retrieving the active link IDs for a detector", func() {
It("should return the correct link IDs", func() {
linkIDs, err = svc.GetAliasedLinkIDsForDetector("ABC", true)
Expect(err).NotTo(HaveOccurred())
Expect(linkIDs).To(Equal([]string{"01", "400", "58", "600", "string"}))
})
})
When("retrieving the link IDs for a non-existing detector", func() {
It("should produce an error", func() {
linkIDs, err = svc.GetAliasedLinkIDsForDetector("NOPE", false)
Expect(err).To(HaveOccurred())
})
})
When("retrieving the link IDs for a detector spelled lower-case", func() {
// not supported
It("should produce an error", func() {
linkIDs, err = svc.GetAliasedLinkIDsForDetector("abc", false)
Expect(err).To(HaveOccurred())
})
})
When("retrieving the link IDs for a detector without readoutcard config", func() {
It("should produce an error", func() {
linkIDs, err = svc.GetAliasedLinkIDsForDetector("DEF", false)
Expect(err).To(HaveOccurred())
})
})
})
// TODO:
// GetRuntimeEntry (currently not supporting yaml backend)
// SetRuntimeEntry (currently not supporting yaml backend)
// GetRuntimeEntries (currently not supporting yaml backend)
// ListRuntimeEntries (currently not supporting yaml backend)
// as far as i can tell, all of those could rather easily support yaml backend and share the code paths with
// the consul backend, thus allow us to test them well without requiring a consul instance
Describe("listing components", func() {
var (
components []string
err error
)
When("the list of components is retrieved", func() {
It("should have the expected components", func() {
components, err = svc.ListComponents()
Expect(err).NotTo(HaveOccurred())
Expect(components).To(ContainElements("qc"))
// there might be also 'readout' in components, but it is put by another Describe node,
// so i would not treat it as guaranteed to be there.
})
})
})
Describe("listing component entries", func() {
var (
query *componentcfg.EntriesQuery
entries []string
err error
)
When("the list of entries for a component is retrieved", func() {
// fixme: the tested function does not perform run type and role name matching, it just takes
// everything under the provided component. i'm not sure if this is correct.
It("should have the expected entries listed in the test yaml file", func() {
query, err = componentcfg.NewEntriesQuery("qc/ANY/any")
entries, err = svc.ListComponentEntries(query)
Expect(err).NotTo(HaveOccurred())
Expect(entries).To(ContainElements(
"ANY/any/entry1",
"ANY/any/entry10",
"ANY/any/entry11",
"ANY/any/entry12",
"ANY/any/sub/entry12",
"ANY/role1/entry1",
"PHYSICS/role1/entry1",
"PHYSICS/role1/entry2",
"TECHNICAL/any/entry",
))
// there might be also a few other elements which are added in different Describe nodes,
// which we do not look for, as they are not guaranteed to be there.
})
})
})
Describe("invalidating template cache", func() {
var (
payload string
query *componentcfg.Query
err error
)
When("requesting an entry after having invalidated cache", func() {
It("should provide a valid entry", func() {
query, err = componentcfg.NewQuery("qc/ANY/any/entry10")
Expect(err).NotTo(HaveOccurred())
varStack := make(map[string]string)
varStack["var1"] = "hello"
payload, err = svc.GetAndProcessComponentConfiguration(query, varStack)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("hello world"))
svc.InvalidateComponentTemplateCache()
payload, err = svc.GetAndProcessComponentConfiguration(query, varStack)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(Equal("hello world"))
})
})
})
})
})