-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_test.go
66 lines (61 loc) · 1.71 KB
/
config_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
63
64
65
66
package common_datalayer
import (
"strings"
"testing"
)
func TestConfig(t *testing.T) {
config, err := loadConfig("./testdata")
if err != nil {
t.Error(err)
}
if config.LayerServiceConfig.ServiceName != "sample" {
t.Error("ServiceName should be sample")
}
if config.NativeSystemConfig["connection"] != "inmemory" {
t.Error("connection should be inmemory")
}
}
func TestConfig_AddEnvOverrides(t *testing.T) {
t.Setenv("PORT", "8000")
t.Setenv("CONFIG_REFRESH_INTERVAL", "60")
t.Setenv("SERVICE_NAME", "my_service")
t.Setenv("STATSD_ENABLED", "true")
t.Setenv("STATSD_AGENT_ADDRESS", "localhost:8125")
t.Setenv("LOG_LEVEL", "debug")
t.Setenv("LOG_FORMAT", "json")
config, err := loadConfig("./testdata")
if err != nil {
t.Error(err)
}
if config.LayerServiceConfig.Port != "8000" {
t.Error("Port should be 8000")
}
if config.LayerServiceConfig.ConfigRefreshInterval != "60" {
t.Error("ConfigRefreshInterval should be 60")
}
if config.LayerServiceConfig.ServiceName != "my_service" {
t.Error("ServiceName should be my_service")
}
if !config.LayerServiceConfig.StatsdEnabled {
t.Error("StatsdEnabled should be true")
}
if config.LayerServiceConfig.StatsdAgentAddress != "localhost:8125" {
t.Error("StatsdAgentAddress should be localhost:8125")
}
if config.LayerServiceConfig.LogLevel != "debug" {
t.Error("LogLevel should be debug")
}
if config.LayerServiceConfig.LogFormat != "json" {
t.Error("LogFormat should be json")
}
}
func TestConfig_PortAsNumber(t *testing.T) {
reader := strings.NewReader(`{ "layer_config": { "port": 8000 } }`)
conf, err := readConfig(reader)
if err != nil {
t.Error(err)
}
if conf.LayerServiceConfig.Port != "8000" {
t.Error("Port should be 8000")
}
}