-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader_plain_test.go
85 lines (68 loc) · 1.93 KB
/
loader_plain_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
// Copyright The ActForGood Authors.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://github.com/actforgood/xconf/blob/main/LICENSE.
package xconf_test
import (
"testing"
"github.com/actforgood/xconf"
)
func TestPlainLoader(t *testing.T) {
t.Parallel()
t.Run("success - explicit map is returned as config", testPlainLoaderSuccess)
t.Run("success - safe-mutable config map", testPlainLoaderReturnsSafeMutableConfigMap)
}
func testPlainLoaderSuccess(t *testing.T) {
t.Parallel()
// arrange
var (
expectedConfig = map[string]any{
"plain_foo": "bar",
"plain_year": 2022,
"plain_temperature": 37.5,
"plain_shopping_list": []string{"bread", "milk", "eggs"},
}
subject = xconf.PlainLoader(expectedConfig)
)
// act
config, err := subject.Load()
// assert
assertNil(t, err)
assertEqual(t, expectedConfig, config)
}
func testPlainLoaderReturnsSafeMutableConfigMap(t *testing.T) {
t.Parallel()
// arrange
var (
expectedConfig = map[string]any{
"plain_string": "some string",
"plain_slice": []string{"foo", "bar", "baz"},
"plain_map": map[string]any{"foo": "bar"},
}
subject = xconf.PlainLoader(expectedConfig)
)
// act
config1, err1 := subject.Load()
// assert
assertNil(t, err1)
assertEqual(t, expectedConfig, config1)
// modify first returned value, expect second returned value to be initial one.
config1["plain_int"] = 12345
config1["plain_string"] = "test plain string"
config1["plain_slice"].([]string)[0] = "test plain slice"
config1["plain_map"].(map[string]any)["foo"] = "test plain map"
// act
config2, err2 := subject.Load()
// assert
assertNil(t, err2)
assertEqual(t, expectedConfig, config2)
assertEqual(
t,
map[string]any{
"plain_string": "some string",
"plain_slice": []string{"foo", "bar", "baz"},
"plain_map": map[string]any{"foo": "bar"},
},
expectedConfig,
)
}