(t *testing.T)
| 347 | } |
| 348 | |
| 349 | func 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 | |
| 381 | func BenchmarkParseDuration(b *testing.B) { |
| 382 | const data = "30s" |
nothing calls this directly
no test coverage detected