json: test WithName

At the moment, the zap configuration ignores the WithName values.
This commit is contained in:
Patrick Ohly 2022-03-29 11:02:11 +02:00
parent d58f42961c
commit 3fe5b3e09d

View File

@ -38,6 +38,7 @@ func TestZapLoggerInfo(t *testing.T) {
msg string
format string
keysValues []interface{}
names []string
}{
{
msg: "test",
@ -59,12 +60,21 @@ func TestZapLoggerInfo(t *testing.T) {
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for duration value argument\",\"v\":0,\"duration\":\"5s\"}\n",
keysValues: []interface{}{"duration", time.Duration(5 * time.Second)},
},
{
msg: "test for WithName",
names: []string{"hello", "world"},
// TODO: log names
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for WithName\",\"v\":0}\n",
},
}
for _, data := range testDataInfo {
var buffer bytes.Buffer
writer := zapcore.AddSync(&buffer)
sampleInfoLogger, _ := NewJSONLogger(writer, nil, nil)
for _, name := range data.names {
sampleInfoLogger = sampleInfoLogger.WithName(name)
}
// nolint:logcheck // The linter cannot and doesn't need to check the key/value pairs.
sampleInfoLogger.Info(data.msg, data.keysValues...)
logStr := buffer.String()