-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnil_test.go
71 lines (67 loc) · 1.52 KB
/
nil_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
package output_test
import (
"github.com/majohn-r/output"
"testing"
)
func TestNewNilBus(t *testing.T) {
t.Run("basic check", func(t *testing.T) {
o := output.NewNilBus()
if o == nil {
t.Error("NewNilBus() should not return nil")
}
})
}
func TestNilWriter_Write(t *testing.T) {
tests := map[string]struct {
nw output.NilWriter
p []byte
wantN int
wantErr bool
}{
"a few bytes": {
nw: output.NilWriter{},
p: []byte{0, 1, 2},
wantN: 3,
wantErr: false,
},
"nil": {
nw: output.NilWriter{},
p: nil,
wantN: 0,
wantErr: false,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
gotN, err := tt.nw.Write(tt.p)
if (err != nil) != tt.wantErr {
t.Errorf("NilWriter.Write() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotN != tt.wantN {
t.Errorf("NilWriter.Write() = %v, want %v", gotN, tt.wantN)
}
})
}
}
func TestNilLogger_All(t *testing.T) {
type args struct {
msg string
fields map[string]any
}
tests := map[string]struct {
nl output.NilLogger
args args
}{"default": {nl: output.NilLogger{}, args: args{}}}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
tt.nl.Debug(tt.args.msg, tt.args.fields)
tt.nl.Error(tt.args.msg, tt.args.fields)
tt.nl.Fatal(tt.args.msg, tt.args.fields)
tt.nl.Info(tt.args.msg, tt.args.fields)
tt.nl.Panic(tt.args.msg, tt.args.fields)
tt.nl.Trace(tt.args.msg, tt.args.fields)
tt.nl.Warning(tt.args.msg, tt.args.fields)
})
}
}