-
Notifications
You must be signed in to change notification settings - Fork 11
/
logger_test.go
73 lines (63 loc) · 1.31 KB
/
logger_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
67
68
69
70
71
72
73
package j8a
import (
"github.com/rs/zerolog"
"os"
"testing"
"time"
)
func TestServerID(t *testing.T) {
os.Setenv("HOSTNAME", "localhost")
Version = "v0.0.0"
initServerID()
want := "f47f7b28"
if ID != want {
t.Errorf("serverID did not properly compute, got %v, want %v", ID, want)
}
}
func TestDefaultLogLevelInit(t *testing.T) {
initLogger()
got := zerolog.GlobalLevel().String()
want := "info"
if got != want {
t.Errorf("default log level not properly initialised, got %v, want %v", got, want)
}
}
func TestLogLevelReset(t *testing.T) {
tests := []struct {
n string
l string
}{
{"trace", "trace"},
{"debug", "debug"},
{"info", "info"},
{"warn", "warn"},
}
for _, tt := range tests {
t.Run(tt.n, func(t *testing.T) {
c := Config{
LogLevel: tt.l,
}
initLogger()
c.validateLogLevel()
Runner = &Runtime{
Config: c,
StateHandler: NewStateHandler(),
}
Runner.StateHandler.setState(Daemon)
Runner.resetLogLevel()
time.Sleep(time.Millisecond * 1000)
got := zerolog.GlobalLevel().String()
want := tt.l
if got != want {
t.Errorf("log level not properly initialised, got %v, want %v", got, want)
}
})
}
}
func TestBadLogLevelPanic(t *testing.T) {
c := Config{
LogLevel: "blah",
}
initLogger()
shouldPanic(t, c.validateLogLevel)
}