-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathulog_test.go
More file actions
80 lines (65 loc) · 1.79 KB
/
ulog_test.go
File metadata and controls
80 lines (65 loc) · 1.79 KB
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
74
75
76
77
78
79
80
// Copyright (c) CattleCloud LLC
// SPDX-License-Identifier: BSD-3-Clause
package ulog
import "testing"
func Test_New(t *testing.T) {
t.Parallel()
log := New("test")
log.E.Fmt("this is %s", "error")
log.W.Fmt("this is %s", "warn")
log.I.Fmt("this is %s", "info")
log.D.Fmt("this is %s", "debug")
log.T.Fmt("should not see %s", "trace")
t.Log("complete")
}
func Test_SetLevel(t *testing.T) {
t.Parallel()
t.Run("error", func(_ *testing.T) {
log := New("test-error", SetLevel(Error))
log.E.Fmt("this is error")
log.W.Fmt("should not see warn")
log.I.Fmt("should not see info")
log.D.Fmt("should not see debug")
log.T.Fmt("should not see trace")
})
t.Run("warn", func(_ *testing.T) {
log := New("test-warn", SetLevel(Warn))
log.E.Fmt("this is error")
log.W.Fmt("this is warn")
log.I.Fmt("should not see info")
log.D.Fmt("should not see debug")
log.T.Fmt("should not see trace")
})
t.Run("info", func(_ *testing.T) {
log := New("test-info", SetLevel(Info))
log.E.Fmt("this is error")
log.W.Fmt("this is warn")
log.I.Fmt("this is info")
log.D.Fmt("should not see debug")
log.T.Fmt("should not see trace")
})
t.Run("debug", func(_ *testing.T) {
log := New("test-debug", SetLevel(Debug))
log.E.Fmt("this is error")
log.W.Fmt("this is warn")
log.I.Fmt("this is info")
log.D.Fmt("this is debug")
log.T.Fmt("should not see trace")
})
t.Run("trace", func(_ *testing.T) {
log := New("test-trace", SetLevel(Trace))
log.E.Fmt("this is error")
log.W.Fmt("this is warn")
log.I.Fmt("this is info")
log.D.Fmt("this is debug")
log.T.Fmt("this is trace")
})
t.Log("complete")
}
func Test_SetNoTimestamp(t *testing.T) {
t.Parallel()
t.Run("shorten", func(_ *testing.T) {
log := New("test-timestamp", SetNoTimestamp())
log.I.Fmt("no timestamp here")
})
}