-
Notifications
You must be signed in to change notification settings - Fork 34
/
level_test.go
96 lines (87 loc) · 1.69 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package loggo_test
import (
gc "gopkg.in/check.v1"
"github.com/juju/loggo/v2"
)
type LevelSuite struct{}
var _ = gc.Suite(&LevelSuite{})
var parseLevelTests = []struct {
str string
level loggo.Level
fail bool
}{{
str: "trace",
level: loggo.TRACE,
}, {
str: "TrAce",
level: loggo.TRACE,
}, {
str: "TRACE",
level: loggo.TRACE,
}, {
str: "debug",
level: loggo.DEBUG,
}, {
str: "DEBUG",
level: loggo.DEBUG,
}, {
str: "info",
level: loggo.INFO,
}, {
str: "INFO",
level: loggo.INFO,
}, {
str: "warn",
level: loggo.WARNING,
}, {
str: "WARN",
level: loggo.WARNING,
}, {
str: "warning",
level: loggo.WARNING,
}, {
str: "WARNING",
level: loggo.WARNING,
}, {
str: "error",
level: loggo.ERROR,
}, {
str: "ERROR",
level: loggo.ERROR,
}, {
str: "critical",
level: loggo.CRITICAL,
}, {
str: "not_specified",
fail: true,
}, {
str: "other",
fail: true,
}, {
str: "",
fail: true,
}}
func (s *LevelSuite) TestParseLevel(c *gc.C) {
for _, test := range parseLevelTests {
level, ok := loggo.ParseLevel(test.str)
c.Assert(level, gc.Equals, test.level)
c.Assert(ok, gc.Equals, !test.fail)
}
}
var levelStringValueTests = map[loggo.Level]string{
loggo.UNSPECIFIED: "UNSPECIFIED",
loggo.DEBUG: "DEBUG",
loggo.TRACE: "TRACE",
loggo.INFO: "INFO",
loggo.WARNING: "WARNING",
loggo.ERROR: "ERROR",
loggo.CRITICAL: "CRITICAL",
loggo.Level(42): "<unknown>", // other values are unknown
}
func (s *LevelSuite) TestLevelStringValue(c *gc.C) {
for level, str := range levelStringValueTests {
c.Assert(level.String(), gc.Equals, str)
}
}