MCPcopy Create free account
hub / github.com/prometheus/common / TestTimeJSON

Function TestTimeJSON

model/time_test.go:349–379  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

347}
348
349func TestTimeJSON(t *testing.T) {
350 tests := []struct {
351 in Time
352 out string
353 }{
354 {Time(1), `0.001`},
355 {Time(-1), `-0.001`},
356 }
357
358 for i, test := range tests {
359 t.Run(strconv.Itoa(i), func(t *testing.T) {
360 b, err := test.in.MarshalJSON()
361 if err != nil {
362 t.Fatalf("Error marshaling time: %v", err)
363 }
364
365 if string(b) != test.out {
366 t.Errorf("Mismatch in marshal expected=%s actual=%s", test.out, b)
367 }
368
369 var tm Time
370 if err := tm.UnmarshalJSON(b); err != nil {
371 t.Fatalf("Error Unmarshaling time: %v", err)
372 }
373
374 if !test.in.Equal(tm) {
375 t.Fatalf("Mismatch after Unmarshal expected=%v actual=%v", test.in, tm)
376 }
377 })
378 }
379}
380
381func BenchmarkParseDuration(b *testing.B) {
382 const data = "30s"

Callers

nothing calls this directly

Calls 4

UnmarshalJSONMethod · 0.95
TimeTypeAlias · 0.85
MarshalJSONMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected