(t *testing.T)
| 409 | } |
| 410 | |
| 411 | func TestEventJSON(t *testing.T) { |
| 412 | body := map[string]any{"a": 123, "b": 456, "c": "test"} |
| 413 | expectedPickedBody := `{"a":123,"c":"test"}` + "\n" |
| 414 | expectedFullBody := `{"a":123,"b":456,"c":"test"}` + "\n" |
| 415 | |
| 416 | scenarios := []testResponseWriteScenario[any]{ |
| 417 | { |
| 418 | name: "no explicit content-type", |
| 419 | status: 200, |
| 420 | headers: nil, |
| 421 | body: body, |
| 422 | expectedStatus: 200, |
| 423 | expectedHeaders: map[string]string{"content-type": "application/json"}, |
| 424 | expectedBody: expectedPickedBody, |
| 425 | }, |
| 426 | { |
| 427 | name: "with explicit content-type (200)", |
| 428 | status: 200, |
| 429 | headers: map[string]string{"content-type": "application/test"}, |
| 430 | body: body, |
| 431 | expectedStatus: 200, |
| 432 | expectedHeaders: map[string]string{"content-type": "application/test"}, |
| 433 | expectedBody: expectedPickedBody, |
| 434 | }, |
| 435 | { |
| 436 | name: "with explicit content-type (400)", // no fields picker |
| 437 | status: 400, |
| 438 | headers: map[string]string{"content-type": "application/test"}, |
| 439 | body: body, |
| 440 | expectedStatus: 400, |
| 441 | expectedHeaders: map[string]string{"content-type": "application/test"}, |
| 442 | expectedBody: expectedFullBody, |
| 443 | }, |
| 444 | } |
| 445 | |
| 446 | for _, s := range scenarios { |
| 447 | testEventResponseWrite(t, s, func(e *router.Event) error { |
| 448 | e.Request.URL.RawQuery = "fields=a,c" // ensures that the picker is invoked |
| 449 | return e.JSON(s.status, s.body) |
| 450 | }) |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | func TestEventXML(t *testing.T) { |
| 455 | scenarios := []testResponseWriteScenario[string]{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…