-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
59 lines (51 loc) · 1.64 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
package corelog
import (
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDefaultConfigWithEnv(t *testing.T) {
os.Setenv("LOG_LEVEL", LevelError)
os.Setenv("LOG_OUTPUT", OutputStdout)
os.Setenv("LOG_FORMAT", FormatJSON)
os.Setenv("LOG_SOURCE", "true")
os.Setenv("LOG_STACKTRACE", "true")
os.Setenv("LOG_NO_COLOR", "true")
t.Cleanup(os.Clearenv)
cfg := DefaultConfig()
assert.Equal(t, LevelError, cfg.Level)
assert.Equal(t, OutputStdout, cfg.Output)
assert.Equal(t, FormatJSON, cfg.Format)
assert.Equal(t, true, cfg.EnableStackTrace)
assert.Equal(t, true, cfg.EnableSource)
assert.Equal(t, true, cfg.DisableColor)
}
func TestSetConfigOverrides(t *testing.T) {
overrides := []string{
"net,level=error,source=true,format=json,invalid",
"core,output=stdout,stacktrace=true,no-color=true",
}
SetConfigOverrides(strings.Join(overrides, ";"))
cfg := GetConfig("")
assert.Equal(t, "", cfg.Level)
assert.Equal(t, "", cfg.Output)
assert.Equal(t, "", cfg.Format)
assert.Equal(t, false, cfg.EnableStackTrace)
assert.Equal(t, false, cfg.EnableSource)
assert.Equal(t, false, cfg.DisableColor)
net := GetConfig("net")
assert.Equal(t, LevelError, net.Level)
assert.Equal(t, "", net.Output)
assert.Equal(t, FormatJSON, net.Format)
assert.Equal(t, false, net.EnableStackTrace)
assert.Equal(t, true, net.EnableSource)
assert.Equal(t, false, net.DisableColor)
core := GetConfig("core")
assert.Equal(t, "", core.Level)
assert.Equal(t, OutputStdout, core.Output)
assert.Equal(t, "", core.Format)
assert.Equal(t, true, core.EnableStackTrace)
assert.Equal(t, false, core.EnableSource)
assert.Equal(t, true, core.DisableColor)
}