-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrawenv_test.go
62 lines (56 loc) · 1.12 KB
/
rawenv_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
package envcnf
import (
"os"
"strings"
"testing"
)
func Test_rawEnv_withprefix(t *testing.T) {
should := rawEnv{
"ACME_FOO": "1",
"ACME_BAR": "2",
}
for k, v := range should {
os.Setenv(k, v)
defer os.Unsetenv(k)
}
is := newRawEnv("ACME_")
for k, v := range should {
isV, ok := is[strings.TrimPrefix(k, "ACME_")]
if !ok {
t.Errorf("Key %s not found", k)
}
if isV != v {
t.Errorf("Value doesn't match: %s(should be: %s)", isV, v)
}
}
}
func Test_rawEnv_noprefix(t *testing.T) {
env := newRawEnv("")
if len(env) == 0 {
t.Error("no environment variables found at all!")
}
}
func Test_rawEnv_newRawEnvWithPrfxSep(t *testing.T) {
env := newRawEnvWithPrfxSep("", "_")
if len(env) == 0 {
t.Error("no environment variables found at all!")
}
}
func Test_rawEnv_getAllWithPrefix(t *testing.T) {
env := rawEnv{
"aa": "c",
"ab": "c",
"ac": "c",
"b": "b",
"ca": "b",
}
res := env.getAllWithPrefix("a")
if len(res) != 3 {
t.Errorf("not all valid values selected: have %d (expected: %d)", len(res), 3)
}
for k, v := range res {
if v != "c" {
t.Errorf("wrong key selected: %s", k)
}
}
}