-
Notifications
You must be signed in to change notification settings - Fork 0
/
configo_test.go
80 lines (68 loc) · 1.45 KB
/
configo_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
package configo_test
import (
"fmt"
"os"
"testing"
"testing/fstest"
"github.com/affanshahid/configo"
"github.com/stretchr/testify/assert"
)
func Example() {
dir := fstest.MapFS{
"default.yml": {
Data: []byte(`
root:
prop1: foo
prop2: 100
prop3: false
prop4:
nestedProp1: 4
`),
},
"production.yml": {
Data: []byte(`
root:
prop2: 200
`),
},
}
os.Setenv("APP_ENV", "production")
err := configo.Initialize(dir, configo.WithDeploymentFromEnv("APP_ENV"))
if err != nil {
panic(err)
}
fmt.Println(configo.MustGetString("root.prop1"))
fmt.Println(configo.MustGetInt("root.prop2"))
fmt.Println(configo.MustGetBool("root.prop3"))
fmt.Println(configo.MustGetInt("root.prop4.nestedProp1"))
// Output:
// foo
// 200
// false
// 4
}
func TestGlobalConfig(t *testing.T) {
dir := fstest.MapFS{
"default.yml": {
Data: []byte(`
root:
prop1: foo
`),
},
}
err := configo.Initialize(dir)
assert.Nilf(t, err, "err should be nil")
assert.Equal(t, "foo", configo.MustGetString("root.prop1"))
}
func TestGlobalConfigParseError(t *testing.T) {
dir := fstest.MapFS{
"default.yml": {
Data: []byte(`
in valid
; hhvc: foo
`),
},
}
err := configo.Initialize(dir)
assert.NotNil(t, err)
}