-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlevel_test.go
68 lines (60 loc) · 2.07 KB
/
level_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
package golog_test
import (
"errors"
"testing"
. "github.com/damianopetrungaro/golog"
)
func TestParseLevel(t *testing.T) {
tests := map[string]struct {
given string
want Level
wantErr error
}{
"parse DEBUG level must return DEBUG": {given: "DEBUG", want: DEBUG, wantErr: nil},
"parse INFO level must return INFO": {given: "INFO", want: INFO, wantErr: nil},
"parse WARN level must return WARN": {given: "WARN", want: WARN, wantErr: nil},
"parse WARNING level must return WARN": {given: "WARNING", want: WARN, wantErr: nil},
"parse ERROR level must return ERROR": {given: "ERROR", want: ERROR, wantErr: nil},
"parse FATAL level must return FATAL": {given: "FATAL", want: FATAL, wantErr: nil},
"parse UNKNOWN level must return an error": {given: "UNKNOWN", want: 0, wantErr: ErrLevelNotParsed},
}
for name, test := range tests {
test := test
t.Run(name, func(t *testing.T) {
got, err := ParseLevel(test.given)
if got != test.want {
t.Error("could not match parsed level")
t.Errorf("got: %s", got)
t.Errorf("want: %s", test.want)
}
if !errors.Is(err, test.wantErr) {
t.Error("could not match error")
t.Errorf("got: %v", err)
t.Errorf("want: %v", test.wantErr)
}
})
}
}
func TestLevel_String(t *testing.T) {
tests := map[string]struct {
given Level
want string
}{
"a DEBUG level must return DEBUG": {given: DEBUG, want: "DEBUG"},
"a INFO level must return INFO": {given: INFO, want: "INFO"},
"a WARN level must return WARN": {given: WARN, want: "WARN"},
"a ERROR level must return ERROR": {given: ERROR, want: "ERROR"},
"a FATAL level must return FATAL": {given: FATAL, want: "FATAL"},
"a UNKNOWN level must return an empty string": {given: 0, want: ""},
}
for name, test := range tests {
test := test
t.Run(name, func(t *testing.T) {
if got := test.given.String(); got != test.want {
t.Error("could not match string level")
t.Errorf("got: %s", got)
t.Errorf("want: %s", test.want)
}
})
}
}