(t *testing.T)
| 457 | } |
| 458 | |
| 459 | func TestJSONEncoderTimeArrays(t *testing.T) { |
| 460 | times := []time.Time{ |
| 461 | time.Unix(1008720000, 0).UTC(), // 2001-12-19 |
| 462 | time.Unix(1040169600, 0).UTC(), // 2002-12-18 |
| 463 | time.Unix(1071619200, 0).UTC(), // 2003-12-17 |
| 464 | } |
| 465 | |
| 466 | tests := []struct { |
| 467 | desc string |
| 468 | encoder TimeEncoder |
| 469 | want string |
| 470 | }{ |
| 471 | { |
| 472 | desc: "epoch", |
| 473 | encoder: EpochTimeEncoder, |
| 474 | want: `[1008720000,1040169600,1071619200]`, |
| 475 | }, |
| 476 | { |
| 477 | desc: "epoch millis", |
| 478 | encoder: EpochMillisTimeEncoder, |
| 479 | want: `[1008720000000,1040169600000,1071619200000]`, |
| 480 | }, |
| 481 | { |
| 482 | desc: "iso8601", |
| 483 | encoder: ISO8601TimeEncoder, |
| 484 | want: `["2001-12-19T00:00:00.000Z","2002-12-18T00:00:00.000Z","2003-12-17T00:00:00.000Z"]`, |
| 485 | }, |
| 486 | { |
| 487 | desc: "rfc3339", |
| 488 | encoder: RFC3339TimeEncoder, |
| 489 | want: `["2001-12-19T00:00:00Z","2002-12-18T00:00:00Z","2003-12-17T00:00:00Z"]`, |
| 490 | }, |
| 491 | } |
| 492 | |
| 493 | for _, tt := range tests { |
| 494 | t.Run(tt.desc, func(t *testing.T) { |
| 495 | cfg := _defaultEncoderConfig |
| 496 | cfg.EncodeTime = tt.encoder |
| 497 | |
| 498 | enc := &jsonEncoder{buf: bufferpool.Get(), EncoderConfig: &cfg} |
| 499 | err := enc.AddArray("array", ArrayMarshalerFunc(func(arr ArrayEncoder) error { |
| 500 | for _, time := range times { |
| 501 | arr.AppendTime(time) |
| 502 | } |
| 503 | return nil |
| 504 | })) |
| 505 | assert.NoError(t, err) |
| 506 | assert.Equal(t, `"array":`+tt.want, enc.buf.String()) |
| 507 | }) |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | func assertJSON(t *testing.T, expected string, enc *jsonEncoder) { |
| 512 | assert.Equal(t, expected, enc.buf.String(), "Encoded JSON didn't match expectations.") |
nothing calls this directly
no test coverage detected