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

Function TestWithPlurals

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

Source from the content-addressed store, hash-verified

171}
172
173func TestWithPlurals(t *testing.T) {
174 out := &bytes.Buffer{}
175 ctx := New(out).
176 With().
177 Objects("objs", []LogObjectMarshaler{fixtureObj{"a", "z", 1}}).
178 Objects("objs_nil", nil).
179 ObjectsV("objs_v", fixtureObj{"A", "Z", 2}).
180 ObjectsV("objs_v_empty").
181 Strs("strs", []string{"foo", "bar"}).
182 Strs("strs_nil", nil).
183 StrsV("strs_v", "baz", "fizz").
184 StrsV("strs_v_empty").
185 Stringers("stringers", []fmt.Stringer{net.IP{127, 0, 0, 1}, time.Time{}.AddDate(0, 1, 2), 1 * time.Second, nil}).
186 Stringers("stringers_nil", nil).
187 StringersV("stringers_v", net.IP{127, 0, 0, 1}, time.Time{}.AddDate(0, 1, 2), 1*time.Second, nil).
188 StringersV("stringers_v_empty").
189 Errs("errs", []error{errors.New("some error"), errors.New("some other error"), nil, loggableError{fmt.Errorf("oops")}, nonLoggableError{fmt.Errorf("whoops"), 401}}).
190 Errs("errs_nil", nil).
191 Bools("bool", []bool{true, false}).
192 Ints("int", []int{1, 2}).
193 Ints8("int8", []int8{2, 3}).
194 Ints16("int16", []int16{3, 4}).
195 Ints32("int32", []int32{4, 5}).
196 Ints64("int64", []int64{5, 6}).
197 Uints("uint", []uint{6, 7}).
198 Uints8("uint8", []uint8{7, 8}).
199 Uints16("uint16", []uint16{8, 9}).
200 Uints32("uint32", []uint32{9, 10}).
201 Uints64("uint64", []uint64{10, 11}).
202 Floats32("float32", []float32{1.1, 2.2}).
203 Floats64("float64", []float64{2.2, 3.3}).
204 Times("time", []time.Time{time.Time{}.AddDate(0, 1, 2), time.Time{}.AddDate(4, 5, 6)}).
205 Durs("dur", []time.Duration{1 * time.Second, 2 * time.Second})
206 log := ctx.Logger()
207 log.Log().Msg("")
208 if got, want := decodeIfBinaryToString(out.Bytes()),
209 `{"objs":[{"Pub":"a","Tag":"z","priv":1}],"objs_nil":[],"objs_v":[{"Pub":"A","Tag":"Z","priv":2}],"objs_v_empty":[],"strs":["foo","bar"],"strs_nil":[],"strs_v":["baz","fizz"],"strs_v_empty":[],"stringers":["127.0.0.1","0001-02-03 00:00:00 +0000 UTC","1s",null],"stringers_nil":[],"stringers_v":["127.0.0.1","0001-02-03 00:00:00 +0000 UTC","1s",null],"stringers_v_empty":[],"errs":["some error","some other error",null,{"l":"OOPS"},"whoops"],"errs_nil":[],"bool":[true,false],"int":[1,2],"int8":[2,3],"int16":[3,4],"int32":[4,5],"int64":[5,6],"uint":[6,7],"uint8":[7,8],"uint16":[8,9],"uint32":[9,10],"uint64":[10,11],"float32":[1.1,2.2],"float64":[2.2,3.3],"time":["0001-02-03T00:00:00Z","0005-06-07T00:00:00Z"],"dur":[1000,2000]}`+"\n"; got != want {
210 t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
211 }
212}
213
214func TestWithReset(t *testing.T) {
215 out := &bytes.Buffer{}

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected