(t *testing.T)
| 449 | } |
| 450 | |
| 451 | func TestTimeJSON(t *testing.T) { |
| 452 | tests := []struct { |
| 453 | in Time |
| 454 | out string |
| 455 | }{ |
| 456 | {Time(1), `0.001`}, |
| 457 | {Time(-1), `-0.001`}, |
| 458 | {Time(1001), `1.001`}, |
| 459 | {Time(-1001), `-1.001`}, |
| 460 | {Time(123000), `123`}, |
| 461 | {Time(123100), `123.1`}, |
| 462 | {Time(123010), `123.01`}, |
| 463 | } |
| 464 | |
| 465 | for i, test := range tests { |
| 466 | t.Run(strconv.Itoa(i), func(t *testing.T) { |
| 467 | b, err := test.in.MarshalJSON() |
| 468 | require.NoErrorf(t, err, "Error marshaling time: %v", err) |
| 469 | |
| 470 | if string(b) != test.out { |
| 471 | t.Errorf("Mismatch in marshal expected=%s actual=%s", test.out, b) |
| 472 | } |
| 473 | |
| 474 | var tm Time |
| 475 | err = tm.UnmarshalJSON(b) |
| 476 | require.NoErrorf(t, err, "Error Unmarshaling time: %v", err) |
| 477 | |
| 478 | require.Truef(t, test.in.Equal(tm), "Mismatch after Unmarshal expected=%v actual=%v", test.in, tm) |
| 479 | }) |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | func BenchmarkParseDuration(b *testing.B) { |
| 484 | const data = "30s" |
nothing calls this directly
no test coverage detected