-
Notifications
You must be signed in to change notification settings - Fork 12
/
environment_test.go
46 lines (37 loc) · 947 Bytes
/
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
package config
import (
"os"
"testing"
)
func TestEnvironmentLoad(t *testing.T) {
os.Setenv("GLOBAL_TIMEOUT", "30")
os.Setenv("GLOBAL_FREQUENCY", "0.5")
os.Setenv("LOCAL_TIME_ZONE", "PST")
os.Setenv("LOCAL_ENABLED", "true")
mappings := map[string]string{
"GLOBAL_TIMEOUT": "global.timeout",
"GLOBAL_FREQUENCY": "global.frequency",
"LOCAL_TIME_ZONE": "local.time_zone",
"LOCAL_ENABLED": "local.enabled",
}
p := NewEnvironment(mappings)
expectedSettings := map[string]string{
"global.timeout": "30",
"global.frequency": "0.5",
"local.time_zone": "PST",
"local.enabled": "true",
}
actualSettings, err := p.Load()
if err != nil {
t.Error(err)
}
for key, expected := range expectedSettings {
actual, ok := actualSettings[key]
if !ok {
t.Errorf("Key '%s' not in settings", key)
}
if actual != expected {
t.Errorf("Setting '%s' was '%s', expected '%s'", key, actual, expected)
}
}
}