-
Notifications
You must be signed in to change notification settings - Fork 0
/
koanfenv_test.go
74 lines (68 loc) · 1.09 KB
/
koanfenv_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
package koanfenv
import (
"testing"
"github.com/stretchr/testify/assert"
)
type config struct {
Foo1 string `koanf:"foo1Koanf" env:"foo1Env"`
Foo2 string `koanf:"" env:"foo2Env"`
Foo3 string `env:"foo3Env"`
Foo4 string `koanf:"-" env:"foo4Env"`
Foo5 string `koanf:"foo5Koanf" env:"-"`
Foo6 string `koanf:"foo6Koanf" env:""`
Foo7 string `koanf:"foo7Koanf"`
Foo8 string
}
func TestEnv2Koanf(t *testing.T) {
conf := config{}
fn := ByStruct(&conf)
cases := []struct {
envTag string
koanfKey string
}{
{
envTag: "foo1Env",
koanfKey: "foo1Koanf",
},
{
envTag: "Foo1Env",
koanfKey: "",
},
{
envTag: "FOO1Env",
koanfKey: "",
},
{
envTag: "foo2Env",
koanfKey: "Foo2",
},
{
envTag: "foo3Env",
koanfKey: "Foo3",
},
{
envTag: "foo4Env",
koanfKey: "",
},
{
envTag: "Foo5",
koanfKey: "",
},
{
envTag: "Foo6",
koanfKey: "",
},
{
envTag: "Foo7",
koanfKey: "",
},
{
envTag: "Foo8",
koanfKey: "",
},
}
for _, c := range cases {
k := fn(c.envTag)
assert.Equal(t, k, c.koanfKey)
}
}