MCPcopy Create free account
hub / github.com/coder/aibridge / TestUpstreamError

Function TestUpstreamError

internal/integrationtest/responses_test.go:666–739  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

664// option.WithMaxRetries(0), in base responses interceptor
665// https://github.com/coder/aibridge/issues/115
666func 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

Callers

nothing calls this directly

Calls 8

newBridgeTestServerFunction · 0.85
responsesRequestBytesFunction · 0.85
HeaderMethod · 0.80
makeRequestMethod · 0.80
GetMethod · 0.80
WriteHeaderMethod · 0.45
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected