-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yusuf Kanchwala
committed
Jul 26, 2020
1 parent
fb4e51a
commit de76066
Showing
2 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package logger | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func TestGetLoggerLevel(t *testing.T) { | ||
table := []struct { | ||
name string | ||
input string | ||
want zapcore.Level | ||
}{ | ||
{ | ||
name: "empty log level", | ||
input: "", | ||
want: zapcore.InfoLevel, | ||
}, | ||
{ | ||
name: "invalid log level", | ||
input: "some log level", | ||
want: zapcore.InfoLevel, | ||
}, | ||
{ | ||
name: "debug log level", | ||
input: "debug", | ||
want: zapcore.DebugLevel, | ||
}, | ||
{ | ||
name: "panic log level", | ||
input: "panic", | ||
want: zapcore.PanicLevel, | ||
}, | ||
} | ||
|
||
for _, tt := range table { | ||
got := getLoggerLevel(tt.input) | ||
if got != tt.want { | ||
t.Errorf("got: '%v', want: '%v'", got, tt.want) | ||
} | ||
} | ||
} | ||
|
||
func TestGetLogger(t *testing.T) { | ||
|
||
table := []struct { | ||
name string | ||
logLevel string | ||
encoding string | ||
encodingLevel func(zapcore.Level, zapcore.PrimitiveArrayEncoder) | ||
}{ | ||
{ | ||
name: "check debug log level", | ||
logLevel: "debug", | ||
encoding: "json", | ||
encodingLevel: zapcore.LowercaseLevelEncoder, | ||
}, | ||
{ | ||
name: "check log level", | ||
logLevel: "panic", | ||
encoding: "console", | ||
encodingLevel: zapcore.LowercaseLevelEncoder, | ||
}, | ||
} | ||
|
||
for _, tt := range table { | ||
got := GetLogger(tt.logLevel, tt.encoding, tt.encodingLevel) | ||
if ce := got.Check(getLoggerLevel(tt.logLevel), "testing"); ce == nil { | ||
t.Errorf("unexpected error") | ||
} | ||
} | ||
} |