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

Function TestFieldsMap

log_test.go:234–268  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func TestFieldsMap(t *testing.T) {
235 out := &bytes.Buffer{}
236 log := New(out)
237 log.Log().Fields(map[string]interface{}{
238 "nil": nil,
239 "string": "foo",
240 "bytes": []byte("bar"),
241 "error": errors.New("some error"),
242 "bool": true,
243 "int": int(1),
244 "int8": int8(2),
245 "int16": int16(3),
246 "int32": int32(4),
247 "int64": int64(5),
248 "uint": uint(6),
249 "uint8": uint8(7),
250 "uint16": uint16(8),
251 "uint32": uint32(9),
252 "uint64": uint64(10),
253 "float32": float32(11),
254 "float64": float64(12),
255 "ipv6": net.IP{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34},
256 "ipnet": 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)},
257 "macaddr": net.HardwareAddr{0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E},
258 "dur": 1 * time.Second,
259 "time": time.Time{},
260 "obj": fixtureObj{"a", "b", 1},
261 "objs": []LogObjectMarshaler{fixtureObj{"a", "b", 1}, fixtureObj{"c", "d", 2}},
262 "any": struct{ A string }{"test"},
263 "raw": json.RawMessage(`{"some":"json"}`),
264 }).Msg("")
265 if got, want := decodeIfBinaryToString(out.Bytes()), `{"any":{"A":"test"},"bool":true,"bytes":"bar","dur":1000,"error":"some error","float32":11,"float64":12,"int":1,"int16":3,"int32":4,"int64":5,"int8":2,"ipnet":"2001:db8:85a3::8a2e:370:7334/64","ipv6":"2001:db8:85a3::8a2e:370:7334","macaddr":"00:1a:2b:3c:4d:5e","nil":null,"obj":{"Pub":"a","Tag":"b","priv":1},"objs":[{"Pub":"a","Tag":"b","priv":1},{"Pub":"c","Tag":"d","priv":2}],"raw":{"some":"json"},"string":"foo","time":"0001-01-01T00:00:00Z","uint":6,"uint16":8,"uint32":9,"uint64":10,"uint8":7}`+"\n"; got != want {
266 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
267 }
268}
269func TestFieldsMap_Arrays(t *testing.T) {
270 out := &bytes.Buffer{}
271 log := New(out)

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