(t *testing.T)
| 289 | } |
| 290 | |
| 291 | func TestJSONEncoderTimeFormats(t *testing.T) { |
| 292 | date := time.Date(2000, time.January, 2, 3, 4, 5, 6, time.UTC) |
| 293 | |
| 294 | f := func(e Encoder) { |
| 295 | e.AddTime("k", date) |
| 296 | err := e.AddArray("a", ArrayMarshalerFunc(func(enc ArrayEncoder) error { |
| 297 | enc.AppendTime(date) |
| 298 | return nil |
| 299 | })) |
| 300 | assert.NoError(t, err) |
| 301 | } |
| 302 | tests := []struct { |
| 303 | desc string |
| 304 | cfg EncoderConfig |
| 305 | expected string |
| 306 | }{ |
| 307 | { |
| 308 | desc: "time.Time ISO8601", |
| 309 | cfg: EncoderConfig{ |
| 310 | EncodeDuration: NanosDurationEncoder, |
| 311 | EncodeTime: ISO8601TimeEncoder, |
| 312 | }, |
| 313 | expected: `"k":"2000-01-02T03:04:05.000Z","a":["2000-01-02T03:04:05.000Z"]`, |
| 314 | }, |
| 315 | { |
| 316 | desc: "time.Time RFC3339", |
| 317 | cfg: EncoderConfig{ |
| 318 | EncodeDuration: NanosDurationEncoder, |
| 319 | EncodeTime: RFC3339TimeEncoder, |
| 320 | }, |
| 321 | expected: `"k":"2000-01-02T03:04:05Z","a":["2000-01-02T03:04:05Z"]`, |
| 322 | }, |
| 323 | { |
| 324 | desc: "time.Time RFC3339Nano", |
| 325 | cfg: EncoderConfig{ |
| 326 | EncodeDuration: NanosDurationEncoder, |
| 327 | EncodeTime: RFC3339NanoTimeEncoder, |
| 328 | }, |
| 329 | expected: `"k":"2000-01-02T03:04:05.000000006Z","a":["2000-01-02T03:04:05.000000006Z"]`, |
| 330 | }, |
| 331 | } |
| 332 | |
| 333 | for _, tt := range tests { |
| 334 | t.Run(tt.desc, func(t *testing.T) { |
| 335 | assertOutput(t, tt.cfg, tt.expected, f) |
| 336 | }) |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | func TestJSONEncoderArrays(t *testing.T) { |
| 341 | tests := []struct { |
nothing calls this directly
no test coverage detected