-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.nul_test.go
84 lines (72 loc) · 1.64 KB
/
adapter.nul_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
74
75
76
77
78
79
80
81
82
83
84
package unilog
import (
"reflect"
"testing"
log "github.com/blugnu/go-logspy"
)
func TestNulAdapter(t *testing.T) {
// ARRANGE
sut := &nulAdapter{}
testcases := []struct {
name string
fn func(string)
}{
{name: "debug", fn: func(s string) { sut.Emit(Debug, s) }},
{name: "info", fn: func(s string) { sut.Emit(Info, s) }},
{name: "warn", fn: func(s string) { sut.Emit(Warn, s) }},
{name: "error", fn: func(s string) { sut.Emit(Error, s) }},
{name: "debug and error", fn: func(s string) { sut.Emit(Debug, s); sut.Emit(Error, s) }},
{name: "withfield", fn: func(s string) {
a := sut
b := sut.WithField("field", "data")
t.Run("returns SAME logger", func(t *testing.T) {
wanted := true
got := a == b
if wanted != got {
t.Errorf("wanted %v, got %v", wanted, got)
}
})
a.Emit(Info, s)
b.Emit(Info, s)
}},
{name: "newentry", fn: func(s string) {
a := sut
b := sut.NewEntry()
t.Run("returns SAME logger", func(t *testing.T) {
wanted := true
got := a == b
if wanted != got {
t.Errorf("wanted %v, got %v", wanted, got)
}
})
a.Emit(Info, s)
b.Emit(Info, s)
}},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
defer log.Reset()
// ACT
tc.fn("entry text")
// ASSERT
wanted := ""
got := log.String()
if wanted != got {
t.Errorf("\nwanted %q\ngot %q", wanted, got)
}
})
}
}
func TestNul(t *testing.T) {
// ACT
result := Nul()
// ASSERT
wanted := &logger{
Context: nil,
Adapter: &nulAdapter{},
}
got := result
if !reflect.DeepEqual(wanted, got) {
t.Errorf("\nwanted %#v\ngot %#v", wanted, got)
}
}