-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_test.go
43 lines (38 loc) · 943 Bytes
/
debug_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
package utils
import (
"os"
"testing"
"github.com/Sirupsen/logrus"
)
func TestEnableDebug(t *testing.T) {
defer func() {
os.Setenv("DEBUG", "")
logrus.SetLevel(logrus.InfoLevel)
}()
EnableDebug()
if os.Getenv("DEBUG") != "1" {
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
}
if logrus.GetLevel() != logrus.DebugLevel {
t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel())
}
}
func TestDisableDebug(t *testing.T) {
DisableDebug()
if os.Getenv("DEBUG") != "" {
t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
}
if logrus.GetLevel() != logrus.InfoLevel {
t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel())
}
}
func TestDebugEnabled(t *testing.T) {
EnableDebug()
if !IsDebugEnabled() {
t.Fatal("expected debug enabled, got false")
}
DisableDebug()
if IsDebugEnabled() {
t.Fatal("expected debug disabled, got true")
}
}