-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenvironment_test.go
58 lines (45 loc) · 1.19 KB
/
environment_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
// (c) 2022 Rick Arnold. Licensed under the BSD license (see LICENSE).
package props
import (
"os"
"testing"
)
func TestEnvironmentGet(t *testing.T) {
e := &Environment{}
os.Setenv("PROPS_TEST_VAL1", "abc")
os.Setenv("PROPS_TEST_VAL2", "")
val, ok := e.Get("PROPS_TEST_VAL1")
if !ok || val != "abc" {
t.Errorf("want: true, 'abc'; got: %t, '%s'", ok, val)
}
val, ok = e.Get("PROPS_TEST_VAL2")
if !ok || val != "" {
t.Errorf("want: true, ''; got: %t, '%s'", ok, val)
}
val, ok = e.Get("PROPS_TEST_VAL3")
if ok || val != "" {
t.Errorf("want: false, ''; got %t, '%s'", ok, val)
}
e.Normalize = true
val, ok = e.Get("props.TEST:val1")
if !ok || val != "abc" {
t.Errorf("want: true, 'abc'; got: %t, '%s'", ok, val)
}
}
func TestEnvironmentGetDefault(t *testing.T) {
e := &Environment{}
os.Setenv("PROPS_TEST_VAL1", "abc")
os.Setenv("PROPS_TEST_VAL2", "")
val := e.GetDefault("PROPS_TEST_VAL1", "zzz")
if val != "abc" {
t.Errorf("want: 'abc'; got: '%s'", val)
}
val = e.GetDefault("PROPS_TEST_VAL2", "def")
if val != "" {
t.Errorf("want: ''; got: '%s'", val)
}
val = e.GetDefault("PROPS_TEST_VAL3", "ghi")
if val != "ghi" {
t.Errorf("want: 'ghi'; got: '%s'", val)
}
}