From bbd9ca16ae8c86925bac400a9504315fe8cc01c4 Mon Sep 17 00:00:00 2001 From: tahsinrahman Date: Wed, 3 Jun 2020 23:14:29 +0800 Subject: [PATCH] Add tests for error in InfoS --- klog.go | 2 +- klog_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/klog.go b/klog.go index ac3fbb0f..d339ea89 100644 --- a/klog.go +++ b/klog.go @@ -802,7 +802,7 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) { b.WriteByte(' ') switch v.(type) { - case string: + case string, error: b.WriteString(fmt.Sprintf("%s=%q", k, v)) default: if _, ok := v.(fmt.Stringer); ok { diff --git a/klog_test.go b/klog_test.go index 40a0ca3c..f46ba915 100644 --- a/klog_test.go +++ b/klog_test.go @@ -18,6 +18,7 @@ package klog import ( "bytes" + "errors" "flag" "fmt" "io/ioutil" @@ -792,6 +793,16 @@ func TestInfoS(t *testing.T) { format: "I0102 15:04:05.067890 1234 klog_test.go:%d] \"test\" replicaNum=20\n", keysValues: []interface{}{"replicaNum", 20}, }, + { + msg: "test", + format: "I0102 15:04:05.067890 1234 klog_test.go:%d] \"test\" err=\"test error\"\n", + keysValues: []interface{}{"err", errors.New("test error")}, + }, + { + msg: "test", + format: "I0102 15:04:05.067890 1234 klog_test.go:%d] \"test\" err=\"test error\"\n", + keysValues: []interface{}{"err", errors.New("test error")}, + }, } for _, data := range testDataInfo {