Skip to content

Commit

Permalink
fix imported bug time encode format form kvlistFormat
Browse files Browse the repository at this point in the history
gofmt

fix failed test case

remove unnecessary variable

add fmt.Stringer support

remove Objref from switch case
  • Loading branch information
yuzhiquan committed Jun 3, 2020
1 parent 2359470 commit 1ccc0e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 9 additions & 3 deletions klog.go
Expand Up @@ -800,10 +800,16 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
v = missingValue
}
b.WriteByte(' ')
if _, ok := v.(fmt.Stringer); ok {

switch v.(type) {
case string:
b.WriteString(fmt.Sprintf("%s=%q", k, v))
} else {
b.WriteString(fmt.Sprintf("%s=%#v", k, v))
default:
if _, ok := v.(fmt.Stringer); ok {
b.WriteString(fmt.Sprintf("%s=%q", k, v))
} else {
b.WriteString(fmt.Sprintf("%s=%+v", k, v))
}
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions klog_test.go
Expand Up @@ -849,20 +849,21 @@ func TestKvListFormat(t *testing.T) {
keysValues: []interface{}{"pod", "kubedns", "spec", struct {
X int
Y string
}{X: 76, Y: "strval"}},
want: " pod=\"kubedns\" spec=struct { X int; Y string }{X:76, Y:\"strval\"}",
N time.Time
}{X: 76, Y: "strval", N: time.Date(2006, 1, 2, 15, 4, 5, .067890e9, time.UTC)}},
want: " pod=\"kubedns\" spec={X:76 Y:strval N:2006-01-02 15:04:05.06789 +0000 UTC}",
},
{
keysValues: []interface{}{"pod", "kubedns", "values", []int{8, 6, 7, 5, 3, 0, 9}},
want: " pod=\"kubedns\" values=[]int{8, 6, 7, 5, 3, 0, 9}",
want: " pod=\"kubedns\" values=[8 6 7 5 3 0 9]",
},
{
keysValues: []interface{}{"pod", "kubedns", "values", []string{"deployment", "svc", "configmap"}},
want: " pod=\"kubedns\" values=[]string{\"deployment\", \"svc\", \"configmap\"}",
want: " pod=\"kubedns\" values=[deployment svc configmap]",
},
{
keysValues: []interface{}{"pod", "kubedns", "maps", map[string]int{"three": 4}},
want: " pod=\"kubedns\" maps=map[string]int{\"three\":4}",
want: " pod=\"kubedns\" maps=map[three:4]",
},
{
keysValues: []interface{}{"pod", KRef("kube-system", "kubedns"), "status", "ready"},
Expand Down

0 comments on commit 1ccc0e1

Please sign in to comment.