-
Notifications
You must be signed in to change notification settings - Fork 2
/
env_sourcer_test.go
45 lines (37 loc) · 1.01 KB
/
env_sourcer_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
package config
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEnvSourcerUnprefixed(t *testing.T) {
os.Setenv("X", "foo")
os.Setenv("Y", "123")
os.Setenv("APP_Y", "456")
sourcer := NewEnvSourcer("app")
require.Nil(t, sourcer.Init())
val1, _, _ := sourcer.Get([]string{"X"})
val2, _, _ := sourcer.Get([]string{"Y"})
assert.Equal(t, "foo", val1)
assert.Equal(t, "456", val2)
}
func TestEnvSourcerNormalizedPrefix(t *testing.T) {
os.Setenv("FOO_BAR_X", "foo")
os.Setenv("FOO_BAR_Y", "123")
sourcer := NewEnvSourcer("$foo-^-bar@")
require.Nil(t, sourcer.Init())
val1, _, _ := sourcer.Get([]string{"X"})
val2, _, _ := sourcer.Get([]string{"Y"})
assert.Equal(t, "foo", val1)
assert.Equal(t, "123", val2)
}
func TestEnvSourcerDump(t *testing.T) {
os.Setenv("X", "foo")
os.Setenv("Y", "123")
sourcer := NewEnvSourcer("app")
require.Nil(t, sourcer.Init())
dump := sourcer.Dump()
assert.Equal(t, "foo", dump["X"])
assert.Equal(t, "123", dump["Y"])
}