Skip to content

Commit 1ccc0e1

Browse files
committedJun 3, 2020
fix imported bug time encode format form kvlistFormat
gofmt fix failed test case remove unnecessary variable add fmt.Stringer support remove Objref from switch case
1 parent 2359470 commit 1ccc0e1

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
 

‎klog.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,16 @@ func kvListFormat(b *bytes.Buffer, keysAndValues ...interface{}) {
800800
v = missingValue
801801
}
802802
b.WriteByte(' ')
803-
if _, ok := v.(fmt.Stringer); ok {
803+
804+
switch v.(type) {
805+
case string:
804806
b.WriteString(fmt.Sprintf("%s=%q", k, v))
805-
} else {
806-
b.WriteString(fmt.Sprintf("%s=%#v", k, v))
807+
default:
808+
if _, ok := v.(fmt.Stringer); ok {
809+
b.WriteString(fmt.Sprintf("%s=%q", k, v))
810+
} else {
811+
b.WriteString(fmt.Sprintf("%s=%+v", k, v))
812+
}
807813
}
808814
}
809815
}

‎klog_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -849,20 +849,21 @@ func TestKvListFormat(t *testing.T) {
849849
keysValues: []interface{}{"pod", "kubedns", "spec", struct {
850850
X int
851851
Y string
852-
}{X: 76, Y: "strval"}},
853-
want: " pod=\"kubedns\" spec=struct { X int; Y string }{X:76, Y:\"strval\"}",
852+
N time.Time
853+
}{X: 76, Y: "strval", N: time.Date(2006, 1, 2, 15, 4, 5, .067890e9, time.UTC)}},
854+
want: " pod=\"kubedns\" spec={X:76 Y:strval N:2006-01-02 15:04:05.06789 +0000 UTC}",
854855
},
855856
{
856857
keysValues: []interface{}{"pod", "kubedns", "values", []int{8, 6, 7, 5, 3, 0, 9}},
857-
want: " pod=\"kubedns\" values=[]int{8, 6, 7, 5, 3, 0, 9}",
858+
want: " pod=\"kubedns\" values=[8 6 7 5 3 0 9]",
858859
},
859860
{
860861
keysValues: []interface{}{"pod", "kubedns", "values", []string{"deployment", "svc", "configmap"}},
861-
want: " pod=\"kubedns\" values=[]string{\"deployment\", \"svc\", \"configmap\"}",
862+
want: " pod=\"kubedns\" values=[deployment svc configmap]",
862863
},
863864
{
864865
keysValues: []interface{}{"pod", "kubedns", "maps", map[string]int{"three": 4}},
865-
want: " pod=\"kubedns\" maps=map[string]int{\"three\":4}",
866+
want: " pod=\"kubedns\" maps=map[three:4]",
866867
},
867868
{
868869
keysValues: []interface{}{"pod", KRef("kube-system", "kubedns"), "status", "ready"},

0 commit comments

Comments
 (0)
Please sign in to comment.