From 6bb29905d7950cfec2998b4885589ec72d13eaf4 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 26 Apr 2023 09:15:26 +0200 Subject: [PATCH] test: add more test cases for map, slice, struct Those are types for which the Sprintf("%+v") catchall code is used. --- test/output.go | 18 ++++++++++++++++++ test/zapr.go | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/output.go b/test/output.go index dff4d421..7cd536fc 100644 --- a/test/output.go +++ b/test/output.go @@ -404,6 +404,24 @@ I output.go:] "test" firstKey=1 secondKey=3 text: "map keys", values: []interface{}{map[string]bool{"test": true}, "test"}, expectedOutput: `I output.go:] "map keys" map[test:%!s(bool=true)]="test" +`, + }, + "map values": { + text: "maps", + values: []interface{}{"s", map[string]string{"hello": "world"}, "i", map[int]int{1: 2, 3: 4}}, + expectedOutput: `I output.go:] "maps" s=map[hello:world] i=map[1:2 3:4] +`, + }, + "slice values": { + text: "slices", + values: []interface{}{"s", []string{"hello", "world"}, "i", []int{1, 2, 3}}, + expectedOutput: `I output.go:] "slices" s=[hello world] i=[1 2 3] +`, + }, + "struct values": { + text: "structs", + values: []interface{}{"s", struct{ Name, Kind, hidden string }{Name: "worker", Kind: "pod", hidden: "ignore"}}, + expectedOutput: `I output.go:] "structs" s={Name:worker Kind:pod hidden:ignore} `, }, } diff --git a/test/zapr.go b/test/zapr.go index c9d47fcc..7d889943 100644 --- a/test/zapr.go +++ b/test/zapr.go @@ -237,6 +237,16 @@ I output.go:] "odd WithValues" keyWithoutValue="(MISSING)" } > `: `{"caller":"test/output.go:","msg":"Format","v":0,"config":{"Kind":"config","RealField":42}} +`, + `I output.go:] "maps" s=map[hello:world] i=map[1:2 3:4] +`: `{"caller":"test/output.go:","msg":"maps","v":0,"s":{"hello":"world"},"i":{"1":2,"3":4}} +`, + + `I output.go:] "slices" s=[hello world] i=[1 2 3] +`: `{"caller":"test/output.go:","msg":"slices","v":0,"s":["hello","world"],"i":[1,2,3]} +`, + `I output.go:] "structs" s={Name:worker Kind:pod hidden:ignore} +`: `{"caller":"test/output.go:","msg":"structs","v":0,"s":{"Name":"worker","Kind":"pod"}} `, } }