Skip to content

Commit

Permalink
test: add more test cases for map, slice, struct
Browse files Browse the repository at this point in the history
Those are types for which the Sprintf("%+v") catchall code is used.
  • Loading branch information
pohly committed Apr 26, 2023
1 parent 77b73d5 commit 6bb2990
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ I output.go:<LINE>] "test" firstKey=1 secondKey=3
text: "map keys",
values: []interface{}{map[string]bool{"test": true}, "test"},
expectedOutput: `I output.go:<LINE>] "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:<LINE>] "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:<LINE>] "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:<LINE>] "structs" s={Name:worker Kind:pod hidden:ignore}
`,
},
}
Expand Down
10 changes: 10 additions & 0 deletions test/zapr.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ I output.go:<LINE>] "odd WithValues" keyWithoutValue="(MISSING)"
}
>
`: `{"caller":"test/output.go:<LINE>","msg":"Format","v":0,"config":{"Kind":"config","RealField":42}}
`,
`I output.go:<LINE>] "maps" s=map[hello:world] i=map[1:2 3:4]
`: `{"caller":"test/output.go:<LINE>","msg":"maps","v":0,"s":{"hello":"world"},"i":{"1":2,"3":4}}
`,

`I output.go:<LINE>] "slices" s=[hello world] i=[1 2 3]
`: `{"caller":"test/output.go:<LINE>","msg":"slices","v":0,"s":["hello","world"],"i":[1,2,3]}
`,
`I output.go:<LINE>] "structs" s={Name:worker Kind:pod hidden:ignore}
`: `{"caller":"test/output.go:<LINE>","msg":"structs","v":0,"s":{"Name":"worker","Kind":"pod"}}
`,
}
}
Expand Down

0 comments on commit 6bb2990

Please sign in to comment.