Skip to content

Commit bbd9ca1

Browse files
committedJun 4, 2020
Add tests for error in InfoS
1 parent db7f626 commit bbd9ca1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎klog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
802802
b.WriteByte(' ')
803803

804804
switch v.(type) {
805-
case string:
805+
case string, error:
806806
b.WriteString(fmt.Sprintf("%s=%q", k, v))
807807
default:
808808
if _, ok := v.(fmt.Stringer); ok {

‎klog_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package klog
1818

1919
import (
2020
"bytes"
21+
"errors"
2122
"flag"
2223
"fmt"
2324
"io/ioutil"
@@ -792,6 +793,16 @@ func TestInfoS(t *testing.T) {
792793
format: "I0102 15:04:05.067890 1234 klog_test.go:%d] \"test\" replicaNum=20\n",
793794
keysValues: []interface{}{"replicaNum", 20},
794795
},
796+
{
797+
msg: "test",
798+
format: "I0102 15:04:05.067890 1234 klog_test.go:%d] \"test\" err=\"test error\"\n",
799+
keysValues: []interface{}{"err", errors.New("test error")},
800+
},
801+
{
802+
msg: "test",
803+
format: "I0102 15:04:05.067890 1234 klog_test.go:%d] \"test\" err=\"test error\"\n",
804+
keysValues: []interface{}{"err", errors.New("test error")},
805+
},
795806
}
796807

797808
for _, data := range testDataInfo {

0 commit comments

Comments
 (0)
Please sign in to comment.