-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_lookup_test.go
More file actions
36 lines (28 loc) · 912 Bytes
/
custom_lookup_test.go
File metadata and controls
36 lines (28 loc) · 912 Bytes
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
package envconfig
import (
"os"
"testing"
)
func TestCustomLookup(t *testing.T) {
t.Run("empty", func(t *testing.T) {
const keyEmpty = "__CUSTOM_LOOKUP_EMPTY_KEY__"
t.Setenv(keyEmpty, "")
_, ignoreExists := IgnoreEmptyEnvLookup(keyEmpty)
_, osExists := os.LookupEnv(keyEmpty)
if ignoreExists == osExists {
t.Fatalf("Expected %q to not exists got %v != %v", keyEmpty, ignoreExists, osExists)
}
})
t.Run("non_empty", func(t *testing.T) {
const keyNotEmpty = "__CUSTOM_LOOKUP_KEY__"
t.Setenv(keyNotEmpty, "__value__")
ignoreVal, ignoreExists := IgnoreEmptyEnvLookup(keyNotEmpty)
osVal, osExists := os.LookupEnv(keyNotEmpty)
if ignoreExists != osExists {
t.Fatalf("Expected %q to not exists got %v != %v", keyNotEmpty, ignoreExists, osExists)
}
if ignoreVal != osVal {
t.Fatalf("Expected %q to have the same values: %v != %v", keyNotEmpty, ignoreVal, osVal)
}
})
}