-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration_test.go
71 lines (64 loc) · 1.48 KB
/
configuration_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
package configurationmanager
import (
"testing"
"github.com/andreasisnes/go-configuration-manager/modules"
"github.com/stretchr/testify/assert"
)
func TestGet(t *testing.T) {
RunTests(t, &[]Test{
{
name: "given two layer with same variable, should return top layer value",
run: func(t *testing.T) {
config := New(nil).
Add(newTestModule(nil, func(m map[string]any) {
m["test-int"] = 10
})).
Add(newTestModule(nil, func(m map[string]any) {
m["test-int"] = 100
})).
Build()
var strPtr *string
config.Get("test-int", &strPtr)
assert.Equal(t, "100", *strPtr)
},
},
{
name: "given a layer with a variable, should return nil if not found",
run: func(t *testing.T) {
config := New(nil).
Add(newTestModule(nil)).
Build()
var strPtr *string = nil
val := config.Get("test", &strPtr)
assert.Nil(t, val)
assert.Nil(t, strPtr)
},
},
})
}
func TestList(t *testing.T) {
RunTests(t, &[]Test{
{
name: "",
run: func(t *testing.T) {
config := New(&Options{
Delimiter: ":",
}).
Add(newTestModule(&modules.Options{
Delimiter: "-",
}, func(m map[string]any) {
m["test-int1"] = 10
})).
Add(newTestModule(&modules.Options{
Delimiter: "?",
}, func(m map[string]any) {
m["test?int2"] = 100
})).
Build()
result := config.List()
assert.Contains(t, result, "test:int1")
assert.Contains(t, result, "test:int2")
},
},
})
}