TODO set MaxRetries to speed up this test option.WithMaxRetries(0), in base responses interceptor https://github.com/coder/aibridge/issues/115
(t *testing.T)
| 664 | // option.WithMaxRetries(0), in base responses interceptor |
| 665 | // https://github.com/coder/aibridge/issues/115 |
| 666 | func TestUpstreamError(t *testing.T) { |
| 667 | t.Parallel() |
| 668 | |
| 669 | responsesError := `{"error":{"message":"Something went wrong","type":"invalid_request_error","param":null,"code":"invalid_request"}}` |
| 670 | nonResponsesError := `plain text error` |
| 671 | |
| 672 | tests := []struct { |
| 673 | name string |
| 674 | streaming bool |
| 675 | statusCode int |
| 676 | contentType string |
| 677 | body string |
| 678 | }{ |
| 679 | { |
| 680 | name: "blocking_responses_error", |
| 681 | streaming: false, |
| 682 | statusCode: http.StatusBadRequest, |
| 683 | contentType: "application/json", |
| 684 | body: responsesError, |
| 685 | }, |
| 686 | { |
| 687 | name: "streaming_responses_error", |
| 688 | streaming: true, |
| 689 | statusCode: http.StatusBadRequest, |
| 690 | contentType: "application/json", |
| 691 | body: responsesError, |
| 692 | }, |
| 693 | { |
| 694 | name: "blocking_non_responses_error", |
| 695 | streaming: false, |
| 696 | statusCode: http.StatusBadGateway, |
| 697 | contentType: "text/plain", |
| 698 | body: nonResponsesError, |
| 699 | }, |
| 700 | { |
| 701 | name: "streaming_non_responses_error", |
| 702 | streaming: true, |
| 703 | statusCode: http.StatusBadGateway, |
| 704 | contentType: "text/plain", |
| 705 | body: nonResponsesError, |
| 706 | }, |
| 707 | } |
| 708 | |
| 709 | for _, tc := range tests { |
| 710 | t.Run(tc.name, func(t *testing.T) { |
| 711 | t.Parallel() |
| 712 | |
| 713 | ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitLong) |
| 714 | t.Cleanup(cancel) |
| 715 | |
| 716 | upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 717 | w.Header().Set("Content-Type", tc.contentType) |
| 718 | w.WriteHeader(tc.statusCode) |
| 719 | _, err := w.Write([]byte(tc.body)) |
| 720 | require.NoError(t, err) |
| 721 | })) |
| 722 | t.Cleanup(upstream.Close) |
| 723 |
nothing calls this directly
no test coverage detected