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

Function TestAppendDurations

internal/json/time_test.go:318–352  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

316 }
317}
318func TestAppendDurations(t *testing.T) {
319 array := make([]time.Duration, len(internal.DurTestcases))
320 want := make([]byte, 0)
321 want = append(want, '[')
322 for i, tt := range internal.DurTestcases {
323 array[i] = tt.Duration
324 whole := int(tt.Duration) / int(time.Microsecond)
325 want = append(want, []byte(fmt.Sprintf("%v", whole))...)
326 if i < len(internal.DurTestcases)-1 {
327 want = append(want, ',')
328 }
329 }
330 want = append(want, ']')
331
332 got := enc.AppendDurations([]byte{}, array, time.Microsecond, "", false, -1)
333 if !bytes.Equal(got, want) {
334 t.Errorf("AppendDurations(%v)\ngot: %s\nwant: %s",
335 array,
336 string(got),
337 string(want))
338 }
339
340 // now empty array case
341 array = make([]time.Duration, 0)
342 want = make([]byte, 0)
343 want = append(want, '[')
344 want = append(want, ']')
345 got = enc.AppendDurations([]byte{}, array, time.Microsecond, "", false, -1)
346 if !bytes.Equal(got, want) {
347 t.Errorf("AppendDurations(%v)\ngot: %s\nwant: %s",
348 array,
349 string(got),
350 string(want))
351 }
352}
353
354func BenchmarkAppendTime(b *testing.B) {
355 tests := map[string]string{

Callers

nothing calls this directly

Calls 1

AppendDurationsMethod · 0.65

Tested by

no test coverage detected