-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_entry_test.go
57 lines (41 loc) · 1.08 KB
/
log_entry_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
package logger
import (
"os"
"testing"
)
func TestShouldPrintWhenLogLevelIsTheSame(t *testing.T) {
os.Setenv("LOG_LEVEL", "info")
entry := LogEntry{
Level: LOG_LEVEL_INFO,
}
want := true
result := entry.shouldPrint()
t.Logf(`LogEntry.shouldPrint() = %t`, result)
if want != result {
t.Fatalf(`LogEntry.shouldPrint() = %t, want = "%t", got = "%t"`, result, want, result)
}
}
func TestShouldNotPrintWhenEnvLogLevelIsHigher(t *testing.T) {
os.Setenv("LOG_LEVEL", "fatal")
entry := LogEntry{
Level: LOG_LEVEL_INFO,
}
result := entry.shouldPrint()
want := false
t.Logf(`LogEntry.shouldPrint() = %t`, result)
if want != result {
t.Fatalf(`LogEntry.shouldPrint() = %t, want = "%t", got = "%t"`, result, want, result)
}
}
func TestShouldPrintWhenEnvLogLevelIsLower(t *testing.T) {
os.Setenv("LOG_LEVEL", "debug")
entry := LogEntry{
Level: LOG_LEVEL_INFO,
}
result := entry.shouldPrint()
want := true
t.Logf(`LogEntry.shouldPrint() = %t`, result)
if want != result {
t.Fatalf(`LogEntry.shouldPrint() = %t, want = "%t", got = "%t"`, result, want, result)
}
}