-
Notifications
You must be signed in to change notification settings - Fork 84
/
dlog_test.go
84 lines (79 loc) · 1.71 KB
/
dlog_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 dlog_test
import (
"bytes"
"fmt"
"os"
"testing"
"github.com/oakmound/oak/v4/dlog"
)
func TestErrorCheck(t *testing.T) {
buff := &bytes.Buffer{}
dlog.DefaultLogger.SetOutput(buff)
dlog.ErrorCheck(nil)
if buff.Len() != 0 {
t.Fatal("error should not have been called on nil error")
}
dlog.ErrorCheck(fmt.Errorf("err"))
if buff.Len() == 0 {
t.Fatal("error should have been called on real error")
}
dlog.DefaultLogger.SetOutput(os.Stdout)
}
func TestParseDebugLevel(t *testing.T) {
type testCase struct {
in string
outLevel dlog.Level
outErrors bool
outErrorStr string
}
tcs := []testCase{
{
in: "info",
outLevel: dlog.INFO,
}, {
in: "InFo",
outLevel: dlog.INFO,
}, {
in: "verbose",
outLevel: dlog.VERBOSE,
}, {
in: "ERROR",
outLevel: dlog.ERROR,
}, {
in: "none",
outLevel: dlog.NONE,
}, {
in: "other",
outErrors: true,
outErrorStr: "invalid input: level",
},
}
for _, tc := range tcs {
tc := tc
t.Run(tc.in, func(t *testing.T) {
lvl, err := dlog.ParseDebugLevel(tc.in)
if tc.outErrors {
if err == nil {
t.Fatal("expected error")
}
if tc.outErrorStr != "" {
if tc.outErrorStr != err.Error() {
t.Fatalf("error did not match: got %v expected %v", err.Error(), tc.outErrorStr)
}
}
return
}
if lvl != tc.outLevel {
t.Fatalf("level did not match: got %v expected %v", lvl, tc.outLevel)
}
})
}
}
func TestDefaultFunctions(t *testing.T) {
// coverage tests, functionality tested elsewhere
dlog.Info("test")
dlog.Verb("test")
dlog.SetLogLevel(dlog.VERBOSE)
dlog.SetOutput(os.Stderr)
dlog.SetFilter(func(s string) bool { return false })
}