MCPcopy
hub / github.com/rs/zerolog / TestFieldsMap_Arrays

Function TestFieldsMap_Arrays

log_test.go:269–299  ·  log_test.go::TestFieldsMap_Arrays
(t *testing.T)

Source from the content-addressed store, hash-verified

267 }
268}
269func TestFieldsMap_Arrays(t *testing.T) {
270 out := &bytes.Buffer{}
271 log := New(out)
272 log.Log().Fields(map[string]interface{}{
273 "strings": []string{"foo"},
274 "bools": []bool{true},
275 "errors": []error{errors.New("some error")},
276 "ints": []int{1},
277 "ints8": []int8{1},
278 "ints16": []int16{3},
279 "ints32": []int32{4},
280 "ints64": []int64{5},
281 "uints": []uint{6},
282 "uint8s": []uint8{44},
283 "uints16": []uint16{8},
284 "uints32": []uint32{9},
285 "uints64": []uint64{10},
286 "floats32": []float32{11},
287 "floats64": []float64{12},
288 "ipv6s": []net.IP{{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34}},
289 "ipnets": []net.IPNet{{IP: net.IP{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34}, Mask: net.CIDRMask(64, 128)}},
290 "macaddrs": []net.HardwareAddr{{0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E}},
291 "durs": []time.Duration{1 * time.Second},
292 "times": []time.Time{{}},
293 "objs": []fixtureObj{{"a", "b", 1}},
294 }).Msg("")
295 // special case: []uint8 are logged as base64 string so we use "," for 44
296 if got, want := decodeIfBinaryToString(out.Bytes()), `{"bools":[true],"durs":[1000],"errors":["some error"],"floats32":[11],"floats64":[12],"ints":[1],"ints16":[3],"ints32":[4],"ints64":[5],"ints8":[1],"ipnets":["2001:db8:85a3::8a2e:370:7334/64"],"ipv6s":["2001:db8:85a3::8a2e:370:7334"],"macaddrs":["ABorPE1e"],"objs":[{"Pub":"a","tag":"b"}],"strings":["foo"],"times":["0001-01-01T00:00:00Z"],"uint8s":",","uints":[6],"uints16":[8],"uints32":[9],"uints64":[10]}`+"\n"; got != want {
297 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
298 }
299}
300
301func TestWithErr(t *testing.T) {
302 var err error = nil

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
LogMethod · 0.65
FieldsMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected