(t *testing.T)
| 585 | } |
| 586 | |
| 587 | func TestTimeEncoders(t *testing.T) { |
| 588 | moment := time.Unix(100, 50005000).UTC() |
| 589 | tests := []struct { |
| 590 | yamlDoc string |
| 591 | expected interface{} // output of serializing moment |
| 592 | }{ |
| 593 | {"timeEncoder: iso8601", "1970-01-01T00:01:40.050Z"}, |
| 594 | {"timeEncoder: ISO8601", "1970-01-01T00:01:40.050Z"}, |
| 595 | {"timeEncoder: millis", 100050.005}, |
| 596 | {"timeEncoder: nanos", int64(100050005000)}, |
| 597 | {"timeEncoder: {layout: 06/01/02 03:04pm}", "70/01/01 12:01am"}, |
| 598 | {"timeEncoder: ''", 100.050005}, |
| 599 | {"timeEncoder: something-random", 100.050005}, |
| 600 | {"timeEncoder: rfc3339", "1970-01-01T00:01:40Z"}, |
| 601 | {"timeEncoder: RFC3339", "1970-01-01T00:01:40Z"}, |
| 602 | {"timeEncoder: rfc3339nano", "1970-01-01T00:01:40.050005Z"}, |
| 603 | {"timeEncoder: RFC3339Nano", "1970-01-01T00:01:40.050005Z"}, |
| 604 | } |
| 605 | |
| 606 | for _, tt := range tests { |
| 607 | cfg := EncoderConfig{} |
| 608 | require.NoError(t, yaml.Unmarshal([]byte(tt.yamlDoc), &cfg), "Unexpected error unmarshaling %q.", tt.yamlDoc) |
| 609 | require.NotNil(t, cfg.EncodeTime, "Unmashalled timeEncoder is nil for %q.", tt.yamlDoc) |
| 610 | assertAppended( |
| 611 | t, |
| 612 | tt.expected, |
| 613 | func(arr ArrayEncoder) { cfg.EncodeTime(moment, arr) }, |
| 614 | "Unexpected output serializing %v with %q.", moment, tt.yamlDoc, |
| 615 | ) |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | func TestTimeEncodersWrongYAML(t *testing.T) { |
| 620 | tests := []string{ |
nothing calls this directly
no test coverage detected