Debian Codegraph @

zapcore/level_test.go

raw symbols SCIP
1 // Copyright (c) 2016 Uber Technologies, Inc.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20
21 package zapcorescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/
22
23 import (
24 "bytesscip-go gomod github.com/golang/go/src go1.19 bytes/"
25 "flagscip-go gomod github.com/golang/go/src go1.19 flag/"
26 "stringsscip-go gomod github.com/golang/go/src go1.19 strings/"
27 "testingscip-go gomod github.com/golang/go/src go1.19 testing/"
28
29 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/"
30 )
31
32 func TestLevelStringscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestLevelString().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
33 tests := map[Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#]string{
34 DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.: "debug",
35 InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.: "info",
36 WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel.: "warn",
37 ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel.: "error",
38 DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel.: "dpanic",
39 PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel.: "panic",
40 FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel.: "fatal",
41 Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#(-42): "Level(-42)",
42 InvalidLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InvalidLevel.: "Level(6)", // InvalidLevel does not have a name
43 }
44
45 for lvl, stringLevel := range tests {
46 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, stringLevel, lvl.Stringscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#String().(), "Unexpected lowercase level string.")
47 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, stringsscip-go gomod github.com/golang/go/src go1.19 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.19 strings/ToUpper().(stringLevel), lvl.CapitalStringscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#CapitalString().(), "Unexpected all-caps level string.")
48 }
49 }
50
51 func TestLevelTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestLevelText().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
52 tests := []struct {
53 text string
54 level Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
55 }{
56 {"debug", DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.},
57 {"info", InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.},
58 {"", InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.}, // make the zero value useful
59 {"warn", WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel.},
60 {"error", ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel.},
61 {"dpanic", DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel.},
62 {"panic", PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel.},
63 {"fatal", FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel.},
64 }
65 for _, tt := range tests {
66 if tt.text != "" {
67 lvl := tt.level
68 marshaled, err := lvl.MarshalTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#MarshalText().()
69 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err, "Unexpected error marshaling level %v to text.", &lvl)
70 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.text, string(marshaled), "Marshaling level %v to text yielded unexpected result.", &lvl)
71 }
72
73 var unmarshaled Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
74 err := unmarshaled.UnmarshalTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#UnmarshalText().([]byte(tt.text))
75 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err, `Unexpected error unmarshaling text %q to level.`, tt.text)
76 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.level, unmarshaled, `Text %q unmarshaled to an unexpected level.`, tt.text)
77 }
78 }
79
80 func TestParseLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestParseLevel().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
81 tests := []struct {
82 text string
83 level Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
84 err string
85 }{
86 {"info", InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel., ""},
87 {"DEBUG", DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel., ""},
88 {"FOO", 0, `unrecognized level: "FOO"`},
89 }
90 for _, tt := range tests {
91 parsedLevel, err := ParseLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ParseLevel().(tt.text)
92 if len(tt.err) == 0 {
93 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
94 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.level, parsedLevel)
95 } else {
96 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.ErrorContainsscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/ErrorContains().(t, err, tt.err)
97 }
98 }
99 }
100
101 func TestCapitalLevelsParsescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestCapitalLevelsParse().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
102 tests := []struct {
103 text string
104 level Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
105 }{
106 {"DEBUG", DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.},
107 {"INFO", InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.},
108 {"WARN", WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel.},
109 {"ERROR", ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel.},
110 {"DPANIC", DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel.},
111 {"PANIC", PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel.},
112 {"FATAL", FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel.},
113 }
114 for _, tt := range tests {
115 var unmarshaled Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
116 err := unmarshaled.UnmarshalTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#UnmarshalText().([]byte(tt.text))
117 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err, `Unexpected error unmarshaling text %q to level.`, tt.text)
118 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.level, unmarshaled, `Text %q unmarshaled to an unexpected level.`, tt.text)
119 }
120 }
121
122 func TestWeirdLevelsParsescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestWeirdLevelsParse().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
123 tests := []struct {
124 text string
125 level Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
126 }{
127 // I guess...
128 {"Debug", DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.},
129 {"Info", InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.},
130 {"Warn", WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel.},
131 {"Error", ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel.},
132 {"Dpanic", DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel.},
133 {"Panic", PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel.},
134 {"Fatal", FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel.},
135
136 // What even is...
137 {"DeBuG", DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.},
138 {"InFo", InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.},
139 {"WaRn", WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel.},
140 {"ErRor", ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel.},
141 {"DpAnIc", DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel.},
142 {"PaNiC", PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel.},
143 {"FaTaL", FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel.},
144 }
145 for _, tt := range tests {
146 var unmarshaled Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
147 err := unmarshaled.UnmarshalTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#UnmarshalText().([]byte(tt.text))
148 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, err, `Unexpected error unmarshaling text %q to level.`, tt.text)
149 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.level, unmarshaled, `Text %q unmarshaled to an unexpected level.`, tt.text)
150 }
151 }
152
153 func TestLevelNilsscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestLevelNils().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
154 var l *Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
155
156 // The String() method will not handle nil level properly.
157 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Panicsscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Panics().(t, func() {
158 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, "Level(nil)", l.Stringscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#String().(), "Unexpected result stringifying nil *Level.")
159 }, "Level(nil).String() should panic")
160
161 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Panicsscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Panics().(t, func() {
162 _, _ = l.MarshalTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#MarshalText().() // should panic
163 }, "Expected to panic when marshalling a nil level.")
164
165 err := l.UnmarshalTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#UnmarshalText().([]byte("debug"))
166 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, errUnmarshalNilLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/errUnmarshalNilLevel., err, "Expected to error unmarshalling into a nil Level.")
167 }
168
169 func TestLevelUnmarshalUnknownTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestLevelUnmarshalUnknownText().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
170 var l Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
171 err := l.UnmarshalTextscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#UnmarshalText().([]byte("foo"))
172 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.ErrorContainsscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/ErrorContains().(t, err, "unrecognized level", "Expected unmarshaling arbitrary text to fail.")
173 }
174
175 func TestLevelAsFlagValuescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestLevelAsFlagValue().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
176 var (
177 buf bytesscip-go gomod github.com/golang/go/src go1.19 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.19 bytes/Buffer#
178 lvl Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
179 )
180 fs := flagscip-go gomod github.com/golang/go/src go1.19 flag/.NewFlagSetscip-go gomod github.com/golang/go/src go1.19 flag/NewFlagSet().("levelTest", flagscip-go gomod github.com/golang/go/src go1.19 flag/.ContinueOnErrorscip-go gomod github.com/golang/go/src go1.19 flag/ContinueOnError.)
181 fs.SetOutputscip-go gomod github.com/golang/go/src go1.19 flag/FlagSet#SetOutput().(&buf)
182 fs.Varscip-go gomod github.com/golang/go/src go1.19 flag/FlagSet#Var().(&lvl, "level", "log level")
183
184 for _, expected := range []Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#{DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel., InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel., WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel., ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel., DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel., PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel., FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel.} {
185 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/NoError().(t, fs.Parsescip-go gomod github.com/golang/go/src go1.19 flag/FlagSet#Parse().([]string{"-level", expected.Stringscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#String().()}))
186 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, expected, lvl, "Unexpected level after parsing flag.")
187 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, expected, lvl.Getscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#Get().(), "Unexpected output using flag.Getter API.")
188 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Emptyscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Empty().(t, buf.Stringscip-go gomod github.com/golang/go/src go1.19 bytes/Buffer#String().(), "Unexpected error output parsing level flag.")
189 buf.Resetscip-go gomod github.com/golang/go/src go1.19 bytes/Buffer#Reset().()
190 }
191
192 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Errorscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Error().(t, fs.Parsescip-go gomod github.com/golang/go/src go1.19 flag/FlagSet#Parse().([]string{"-level", "nope"}))
193 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(
194 t,
195 `invalid value "nope" for flag -level: unrecognized level: "nope"`,
196 stringsscip-go gomod github.com/golang/go/src go1.19 strings/.Splitscip-go gomod github.com/golang/go/src go1.19 strings/Split().(buf.Stringscip-go gomod github.com/golang/go/src go1.19 bytes/Buffer#String().(), "\n")[0], // second line is help message
197 "Unexpected error output from invalid flag input.",
198 )
199 }
200
201 // enablerWithCustomLevel is a LevelEnabler that implements a custom Level
202 // method.
203 type enablerWithCustomLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel# struct{ lvlscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#lvl. Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level# }
204
205 var _ leveledEnablerscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/leveledEnabler# = (*enablerWithCustomLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#)(nil)
206
207 func (l *enablerWithCustomLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#) Enabledscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#Enabled().(lvl Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#) bool {
208 return l.lvlscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#lvl..Enabledscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#Enabled().(lvl)
209 }
210
211 func (l *enablerWithCustomLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#) Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#Level().() Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level# {
212 return l.lvlscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#lvl.
213 }
214
215 func TestLevelOfscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/TestLevelOf().(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
216 tests := []struct {
217 desc string
218 give LevelEnablerscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/LevelEnabler#
219 want Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#
220 }{
221 {desc: "debug", give: DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel., want: DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.},
222 {desc: "info", give: InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel., want: InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.},
223 {desc: "warn", give: WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel., want: WarnLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/WarnLevel.},
224 {desc: "error", give: ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel., want: ErrorLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/ErrorLevel.},
225 {desc: "dpanic", give: DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel., want: DPanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DPanicLevel.},
226 {desc: "panic", give: PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel., want: PanicLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/PanicLevel.},
227 {desc: "fatal", give: FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel., want: FatalLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/FatalLevel.},
228 {
229 desc: "leveledEnabler",
230 give: &enablerWithCustomLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#{lvlscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/enablerWithCustomLevel#lvl.: InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.},
231 want: InfoLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InfoLevel.,
232 },
233 {
234 desc: "noop",
235 give: NewNopCorescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/NewNopCore().(), // always disabled
236 want: InvalidLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/InvalidLevel.,
237 },
238 }
239
240 for _, tt := range tests {
241 tt := tt
242 t.Runscip-go gomod github.com/golang/go/src go1.19 testing/T#Run().(tt.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Tscip-go gomod github.com/golang/go/src go1.19 testing/T#) {
243 t.Parallelscip-go gomod github.com/golang/go/src go1.19 testing/T#Parallel().()
244
245 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.want, LevelOfscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/LevelOf().(tt.give), "Reported level did not match.")
246 })
247 }
248 }