Skip to content

Commit

Permalink
Add tests for error in InfoS
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsinrahman committed Jun 4, 2020
1 parent db7f626 commit bbd9ca1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion klog.go
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions klog_test.go
Expand Up @@ -18,6 +18,7 @@ package klog

import (
"bytes"
"errors"
"flag"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bbd9ca1

Please sign in to comment.