-
Notifications
You must be signed in to change notification settings - Fork 34
/
main_racing_test.go
42 lines (34 loc) · 1.09 KB
/
main_racing_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
//go:build !race
// +build !race
package main
import (
"testing"
log "github.com/sirupsen/logrus"
)
func TestLogLevelParsing(t *testing.T) {
t.Parallel()
var debug, fatal bool
_, _, debug = parseArgsAndLoadConfig([]string{"-l", "debug"})
if !(debug == true && log.GetLevel() == log.DebugLevel) {
t.Errorf("failed to set debug flag for debug log level")
}
_, _, debug = parseArgsAndLoadConfig([]string{"-D"})
if !(debug == true && log.GetLevel() == log.DebugLevel) {
t.Errorf("failed to set debug log level for debug flag")
}
_, _, debug = parseArgsAndLoadConfig([]string{"-l", "error"})
if !(debug == false && log.GetLevel() == log.ErrorLevel) {
t.Errorf("failed to set error log level")
}
log.StandardLogger().ExitFunc = func(int) { fatal = true }
_, _, _ = parseArgsAndLoadConfig([]string{"-l", "error", "-D"})
if fatal != true {
t.Errorf("did not fail for mismatched log level and debug flag")
}
fatal = false
_, _, _ = parseArgsAndLoadConfig([]string{"-l", "foo"})
if fatal != true {
t.Errorf("did not fail for invalid log level")
}
log.StandardLogger().ExitFunc = nil
}