-
Notifications
You must be signed in to change notification settings - Fork 10
/
config_test.go
666 lines (532 loc) · 22.2 KB
/
config_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
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
660
661
662
663
664
665
666
/*
Copyright © 2021, 2022, 2023 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main_test
// Unit test definitions for functions and methods defined in source file
// config.go
//
// Documentation in literate-programming-style is available at:
// https://redhatinsights.github.io/ccx-notification-writer/packages/config_test.html
import (
"fmt"
"os"
"testing"
clowder "github.com/redhatinsights/app-common-go/pkg/api/v1"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
main "github.com/RedHatInsights/ccx-notification-writer"
)
// init function is called before tests
func init() {
// set default logging level regardles of config made in code
zerolog.SetGlobalLevel(zerolog.WarnLevel)
}
// mustLoadConfiguration function loads configuration file or the actual test
// will fail
func mustLoadConfiguration(envVar string) {
_, err := main.LoadConfiguration(envVar, "tests/config1")
if err != nil {
panic(err)
}
}
// mustSetEnv function set specified environment variable or the actual test
// will fail
func mustSetEnv(t *testing.T, key, val string) {
err := os.Setenv(key, val)
assert.NoError(t, err)
if err != nil {
t.Fatal(err)
}
}
// TestLoadDefaultConfiguration test loads a configuration file for testing
// with check that load was correct
func TestLoadDefaultConfiguration(_ *testing.T) {
os.Clearenv()
mustLoadConfiguration("nonExistingEnvVar")
}
// TestLoadConfigurationFromEnvVariable tests loading the config. file for
// testing from an environment variable
func TestLoadConfigurationFromEnvVariable(t *testing.T) {
os.Clearenv()
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
mustLoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE")
}
// TestLoadConfigurationNonEnvVarUnknownConfigFile tests loading an unexisting
// config file when no environment variable is provided
func TestLoadConfigurationNonEnvVarUnknownConfigFile(t *testing.T) {
_, err := main.LoadConfiguration("", "foobar")
assert.Nil(t, err)
}
// TestLoadConfigurationBadConfigFile tests loading an unexisting config file
// when no environment variable is provided
func TestLoadConfigurationBadConfigFile(t *testing.T) {
_, err := main.LoadConfiguration("", "tests/config3")
assert.Contains(t, err.Error(), `fatal error config file: While parsing config:`)
}
// TestLoadingConfigurationEnvVariableBadValueNoDefaultConfig tests loading a
// non-existent configuration file set in environment
func TestLoadingConfigurationEnvVariableBadValueNoDefaultConfig(t *testing.T) {
os.Clearenv()
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "non existing file")
_, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "")
assert.Contains(t, err.Error(), `fatal error config file: Config File "non existing file" Not Found in`)
}
// TestLoadingConfigurationEnvVariableBadValueNoDefaultConfig tests that if env
// var is provided, it must point to a valid config file
func TestLoadingConfigurationEnvVariableBadValueDefaultConfigFailure(t *testing.T) {
os.Clearenv()
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "non existing file")
_, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config1")
assert.Contains(t, err.Error(), `fatal error config file: Config File "non existing file" Not Found in`)
}
// TestLoadBrokerConfiguration tests loading the broker configuration sub-tree
func TestLoadBrokerConfiguration(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
brokerCfg := main.GetBrokerConfiguration(&config)
assert.Equal(t, "localhost:29092", brokerCfg.Addresses)
assert.Equal(t, "ccx_test_notifications", brokerCfg.Topic)
}
// TestLoadStorageConfiguration tests loading the storage configuration
// subtree
func TestLoadStorageConfiguration(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
storageCfg := main.GetStorageConfiguration(&config)
assert.Equal(t, "sqlite3", storageCfg.Driver)
assert.Equal(t, "user", storageCfg.PGUsername)
assert.Equal(t, "password", storageCfg.PGPassword)
assert.Equal(t, "localhost", storageCfg.PGHost)
assert.Equal(t, 5432, storageCfg.PGPort)
assert.Equal(t, "notifications", storageCfg.PGDBName)
assert.Equal(t, "", storageCfg.PGParams)
assert.Equal(t, true, storageCfg.LogSQLQueries)
}
// TestLoadLoggingConfiguration tests loading the logging configuration sub-tree
func TestLoadLoggingConfiguration(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
loggingCfg := main.GetLoggingConfiguration(&config)
assert.Equal(t, true, loggingCfg.Debug)
assert.Equal(t, "", loggingCfg.LogLevel)
}
// TestLoadCloudwatchConfiguration tests loading the Cloudwatch configuration sub-tree
func TestLoadCloudwatchConfiguration(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
cfg := main.GetCloudWatchConfiguration(&config)
assert.Equal(t, false, cfg.Debug)
assert.Equal(t, "aws_secret", cfg.AWSSecretKey)
assert.Equal(t, "aws_access_id", cfg.AWSAccessID)
assert.Equal(t, "test_stream", cfg.StreamName)
assert.Equal(t, "test_group", cfg.LogGroup)
}
// TestLoadMetricsConfiguration tests loading the metrics configuration sub-tree
func TestLoadMetricsConfiguration(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
metricsCfg := main.GetMetricsConfiguration(&config)
assert.Equal(t, "notification_writer", metricsCfg.Namespace)
assert.Equal(t, ":8080", metricsCfg.Address)
}
// TestLoadConfigurationFromEnvVariableClowderEnabled tests loading the config.
// file for testing from an environment variable. Clowder config is enabled in
// this case.
func TestLoadConfigurationFromEnvVariableClowderEnabled(t *testing.T) {
var testDB = "test_db"
os.Clearenv()
// explicit database configuration
clowder.LoadedConfig = &clowder.AppConfig{
Database: &clowder.DatabaseConfig{
Name: testDB,
},
}
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
// load configuration using Clowder config
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
// check if database configuration has been loaded properly
dbCfg := main.GetStorageConfiguration(&config)
assert.Equal(t, testDB, dbCfg.PGDBName)
}
// TestLoadConfigurationNoKafkaBroker test if number of configured brokers are
// tested properly when no broker config exists
func TestLoadConfigurationNoKafkaBroker(t *testing.T) {
var testDB = "test_db"
os.Clearenv()
// explicit database and broker configuration
clowder.LoadedConfig = &clowder.AppConfig{
Database: &clowder.DatabaseConfig{
Name: testDB,
},
Kafka: &clowder.KafkaConfig{}, // no brokers in configuration
}
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
// load configuration using Clowder config
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
// retrieve broker configuration that was just loaded
brokerCfg := main.GetBrokerConfiguration(&config)
// check broker configuration
assert.Equal(t, "localhost:29092", brokerCfg.Addresses)
assert.Equal(t, "ccx_test_notifications", brokerCfg.Topic)
assert.Equal(t, "test-consumer-group", brokerCfg.Group)
assert.True(t, brokerCfg.Enabled)
}
// TestLoadConfigurationKafkaBrokerEmptyConfig test if empty broker config is
// loaded via Clowder
func TestLoadConfigurationKafkaBrokerEmptyConfig(t *testing.T) {
var testDB = "test_db"
os.Clearenv()
// just one empty broker configuration
var brokersConfig = []clowder.BrokerConfig{
{},
}
// explicit database and broker configuration
clowder.LoadedConfig = &clowder.AppConfig{
Database: &clowder.DatabaseConfig{
Name: testDB,
},
Kafka: &clowder.KafkaConfig{
Brokers: brokersConfig,
Topics: []clowder.TopicConfig{},
},
}
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
// load configuration using Clowder config
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
// retrieve broker configuration that was just loaded
brokerCfg := main.GetBrokerConfiguration(&config)
print(clowder.KafkaServers)
print(clowder.LoadedConfig.Kafka)
// check broker configuration
assert.Equal(t, "", brokerCfg.Addresses)
assert.Equal(t, "ccx_test_notifications", brokerCfg.Topic)
assert.Equal(t, "test-consumer-group", brokerCfg.Group)
assert.True(t, brokerCfg.Enabled)
}
// TestLoadConfigurationKafkaBrokerNoPort test loading broker configuration w/o port
func TestLoadConfigurationKafkaBrokerNoPort(t *testing.T) {
var testDB = "test_db"
os.Clearenv()
// just one non-empty broker configuration
var brokersConfig = []clowder.BrokerConfig{
{
Hostname: "test",
Port: nil}, // port is not set
}
// explicit database and broker configuration
clowder.LoadedConfig = &clowder.AppConfig{
Database: &clowder.DatabaseConfig{
Name: testDB,
},
Kafka: &clowder.KafkaConfig{
Brokers: brokersConfig},
}
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
// load configuration using Clowder config
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
// retrieve broker configuration that was just loaded
brokerCfg := main.GetBrokerConfiguration(&config)
// check broker configuration
// no port should be set
assert.Equal(t, "test", brokerCfg.Addresses)
assert.Equal(t, "ccx_test_notifications", brokerCfg.Topic)
assert.Equal(t, "test-consumer-group", brokerCfg.Group)
assert.True(t, brokerCfg.Enabled)
}
// TestLoadConfigurationKafkaBrokerPort test loading broker port
func TestLoadConfigurationKafkaBrokerPort(t *testing.T) {
var testDB = "test_db"
os.Clearenv()
var port = 1234
// just one non-empty broker configuration
var brokersConfig []clowder.BrokerConfig = []clowder.BrokerConfig{
{
Hostname: "test",
Port: &port}, // port is set
}
// explicit database and broker configuration
clowder.LoadedConfig = &clowder.AppConfig{
Database: &clowder.DatabaseConfig{
Name: testDB,
},
Kafka: &clowder.KafkaConfig{
Brokers: brokersConfig},
}
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
// load configuration using Clowder config
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
// retrieve broker configuration that was just loaded
brokerCfg := main.GetBrokerConfiguration(&config)
// check broker configuration
assert.Equal(t, "test:1234", brokerCfg.Addresses)
assert.Equal(t, "ccx_test_notifications", brokerCfg.Topic)
assert.Equal(t, "test-consumer-group", brokerCfg.Group)
assert.True(t, brokerCfg.Enabled)
}
// TestLoadConfigurationKafkaBrokerAuthConfigMissingSASL test loading broker auth. config
// is correct but missing SASL configuration
func TestLoadConfigurationKafkaBrokerAuthConfigMissingSASL(t *testing.T) {
var testDB = "test_db"
os.Clearenv()
var port = 1234
var authType clowder.BrokerConfigAuthtype
var brokersConfig []clowder.BrokerConfig = []clowder.BrokerConfig{
{
Hostname: "test",
Port: &port,
Authtype: &authType,
},
}
// explicit database and broker configuration
clowder.LoadedConfig = &clowder.AppConfig{
Database: &clowder.DatabaseConfig{
Name: testDB,
},
Kafka: &clowder.KafkaConfig{
Brokers: brokersConfig,
},
}
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
// load configuration using Clowder config
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
// retrieve broker configuration that was just loaded
brokerCfg := main.GetBrokerConfiguration(&config)
// check broker configuration
assert.Equal(t, "test:1234", brokerCfg.Addresses)
assert.Equal(t, "ccx_test_notifications", brokerCfg.Topic)
assert.Equal(t, "test-consumer-group", brokerCfg.Group)
assert.True(t, brokerCfg.Enabled)
// additionally SASL config should be set too
assert.Equal(t, "", brokerCfg.SaslUsername)
assert.Equal(t, "", brokerCfg.SaslPassword)
assert.Equal(t, "", brokerCfg.SaslMechanism)
assert.Equal(t, "", brokerCfg.SecurityProtocol)
}
// TestLoadConfigurationKafkaBrokerAuthConfig test loading broker auth. config
// is correct
func TestLoadConfigurationKafkaBrokerAuthConfig(t *testing.T) {
var testDB = "test_db"
os.Clearenv()
var port = 1234
var authType clowder.BrokerConfigAuthtype
var username = "username"
var password = "password"
var saslMechanism = "mechanism"
var securityProtocol = "security_protocol"
var brokersConfig []clowder.BrokerConfig = []clowder.BrokerConfig{
{
Hostname: "test",
Port: &port,
Authtype: &authType,
SecurityProtocol: &securityProtocol,
// proper SASL configuration
Sasl: &clowder.KafkaSASLConfig{
Username: &username,
Password: &password,
SaslMechanism: &saslMechanism,
},
},
}
// explicit database and broker configuration
clowder.LoadedConfig = &clowder.AppConfig{
Database: &clowder.DatabaseConfig{
Name: testDB,
},
Kafka: &clowder.KafkaConfig{
Brokers: brokersConfig,
},
}
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, "CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
// load configuration using Clowder config
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
// retrieve broker configuration that was just loaded
brokerCfg := main.GetBrokerConfiguration(&config)
// check broker configuration
assert.Equal(t, "test:1234", brokerCfg.Addresses)
assert.Equal(t, "ccx_test_notifications", brokerCfg.Topic)
assert.Equal(t, "test-consumer-group", brokerCfg.Group)
assert.True(t, brokerCfg.Enabled)
// additionally SASL config should be set too
assert.Equal(t, username, brokerCfg.SaslUsername)
assert.Equal(t, password, brokerCfg.SaslPassword)
assert.Equal(t, saslMechanism, brokerCfg.SaslMechanism)
assert.Equal(t, securityProtocol, brokerCfg.SecurityProtocol)
}
// TestLoadConfigurationKafkaTopicUpdatedFromClowder tests that when applying the config,
// if the Clowder config is enabled, the Kafka topics are replaced by the ones defined in
// LoadedConfig.Kafka.Topics if found, and used as-is if not.
func TestLoadConfigurationKafkaTopicUpdatedFromClowder(t *testing.T) {
os.Clearenv()
hostname := "kafka"
port := 9092
topicName := "ccx_test_notifications"
newTopicName := "the.clowder.kafka.topic"
// explicit database and broker config
clowder.LoadedConfig = &clowder.AppConfig{
Kafka: &clowder.KafkaConfig{
Brokers: []clowder.BrokerConfig{
{
Hostname: hostname,
Port: &port,
},
},
},
}
clowder.KafkaTopics = make(map[string]clowder.TopicConfig)
clowder.KafkaTopics[topicName] = clowder.TopicConfig{
Name: newTopicName,
RequestedName: topicName,
}
// set environment variable that points to Clowder configuration file
mustSetEnv(t, "ACG_CONFIG", "tests/clowder_config.json")
config, err := main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config2")
assert.NoError(t, err, "Failed loading configuration file")
brokerCfg := main.GetBrokerConfiguration(&config)
assert.Equal(t, fmt.Sprintf("%s:%d", hostname, port), brokerCfg.Addresses)
assert.Equal(t, newTopicName, brokerCfg.Topic)
// config with different broker configuration, broker's hostname taken from clowder, but no topic to map to
topicName = "test_notification_topic"
config, err = main.LoadConfiguration("CCX_NOTIFICATION_WRITER_CONFIG_FILE", "tests/config1")
assert.NoError(t, err, "Failed loading configuration file")
brokerCfg = main.GetBrokerConfiguration(&config)
assert.Equal(t, fmt.Sprintf("%s:%d", hostname, port), brokerCfg.Addresses)
assert.Equal(t, topicName, brokerCfg.Topic)
}
// TestGetStorageConfigurationIsImmutable checks if function
// GetStorageConfiguration is not mutable
func TestGetStorageConfigurationIsImmutable(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
// load configuration with check if loading was ok
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
// clone the configuration
origConfig := config
// call the tested function
main.GetStorageConfiguration(&config)
// and compare original configuration with possibly mutated one
assert.Equal(t, config, origConfig, "GetStorageConfiguration must not be mutable")
}
// TestGetLoggingConfigurationIsImmutable checks if function
// GetLoggingConfiguration is not mutable
func TestGetLoggingConfigurationIsImmutable(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
// load configuration with check if loading was ok
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
// clone the configuration
origConfig := config
// call the tested function
main.GetLoggingConfiguration(&config)
// and compare original configuration with possibly mutated one
assert.Equal(t, config, origConfig, "GetLoggingConfiguration must not be mutable")
}
// TestGetBrokerConfigurationIsImmutable checks if function
// GetBrokerConfiguration is not mutable
func TestGetBrokerConfigurationIsImmutable(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
// load configuration with check if loading was ok
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
// clone the configuration
origConfig := config
// call the tested function
main.GetBrokerConfiguration(&config)
// and compare original configuration with possibly mutated one
assert.Equal(t, config, origConfig, "GetBrokerConfiguration must not be mutable")
}
// TestGetMetricsConfigurationIsImmutable checks if function
// GetMetricsConfiguration is not mutable
func TestGetMetricsConfigurationIsImmutable(t *testing.T) {
envVar := "CCX_NOTIFICATION_WRITER_CONFIG_FILE"
// set environment variable that points to config file
// (without extension)
mustSetEnv(t, envVar, "tests/config2")
// load configuration with check if loading was ok
config, err := main.LoadConfiguration(envVar, "")
assert.Nil(t, err, "Failed loading configuration file from env var!")
// clone the configuration
origConfig := config
// call the tested function
main.GetMetricsConfiguration(&config)
// and compare original configuration with possibly mutated one
assert.Equal(t, config, origConfig, "GetMetricsConfiguration must not be mutable")
}