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

Function TestFieldsArrayMultipleElement

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

Source from the content-addressed store, hash-verified

628}
629
630func TestFieldsArrayMultipleElement(t *testing.T) {
631 out := &bytes.Buffer{}
632 log := New(out)
633 log.Log().
634 Objects("objs", []LogObjectMarshaler{fixtureObj{"a", "z", 1}, fixtureObj{"b", "y", 2}}).
635 ObjectsV("objs_v", fixtureObj{"A", "Z", 3}, fixtureObj{"B", "Y", 4}).
636 Strs("strs", []string{"foo", "bar"}).
637 StrsV("strs_v", "baz", "fizz").
638 Stringers("stringers", []fmt.Stringer{nil, net.IP{127, 0, 0, 1}}).
639 StringersV("stringers_v", net.IPv4bcast, net.IPv6loopback).
640 Errs("err", []error{errors.New("some error"), nil}).
641 Bools("bool", []bool{true, false}).
642 Ints("int", []int{1, 0}).
643 Ints8("int8", []int8{2, 0}).
644 Ints16("int16", []int16{3, 0}).
645 Ints32("int32", []int32{4, 0}).
646 Ints64("int64", []int64{5, 0}).
647 Uints("uint", []uint{6, 0}).
648 Uints8("uint8", []uint8{7, 0}).
649 Uints16("uint16", []uint16{8, 0}).
650 Uints32("uint32", []uint32{9, 0}).
651 Uints64("uint64", []uint64{10, 0}).
652 Floats32("float32", []float32{11, 0}).
653 Floats64("float64", []float64{12, 0}).
654 Durs("dur", []time.Duration{1 * time.Second, 0}).
655 Times("time", []time.Time{{}, {}}).
656 IPAddrs("ip", []net.IP{{192, 168, 0, 100}, {0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34}}).
657 IPPrefixes("pfx", []net.IPNet{{IP: net.IP{192, 168, 0, 100}, Mask: net.CIDRMask(24, 32)}, {IP: net.IP{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34}, Mask: net.CIDRMask(64, 128)}}).
658 Msg("")
659 if got, want := decodeIfBinaryToString(out.Bytes()), `{"objs":[{"Pub":"a","Tag":"z","priv":1},{"Pub":"b","Tag":"y","priv":2}],"objs_v":[{"Pub":"A","Tag":"Z","priv":3},{"Pub":"B","Tag":"Y","priv":4}],"strs":["foo","bar"],"strs_v":["baz","fizz"],"stringers":[null,"127.0.0.1"],"stringers_v":["255.255.255.255","::1"],"err":["some error",null],"bool":[true,false],"int":[1,0],"int8":[2,0],"int16":[3,0],"int32":[4,0],"int64":[5,0],"uint":[6,0],"uint8":[7,0],"uint16":[8,0],"uint32":[9,0],"uint64":[10,0],"float32":[11,0],"float64":[12,0],"dur":[1000,0],"time":["0001-01-01T00:00:00Z","0001-01-01T00:00:00Z"],"ip":["192.168.0.100","2001:db8:85a3::8a2e:370:7334"],"pfx":["192.168.0.100/24","2001:db8:85a3::8a2e:370:7334/64"]}`+"\n"; got != want {
660 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
661 }
662}
663
664func TestFieldsDisabled(t *testing.T) {
665 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 15

NewFunction · 0.85
MsgMethod · 0.80
decodeIfBinaryToStringFunction · 0.70
LogMethod · 0.65
IPPrefixesMethod · 0.45
IPAddrsMethod · 0.45
TimesMethod · 0.45
DursMethod · 0.45
Floats64Method · 0.45
Floats32Method · 0.45
Uints64Method · 0.45
Uints32Method · 0.45

Tested by

no test coverage detected