fakeOpenAIUpstream returns an httptest.Server that decodes the inbound request as an openAIRequest, calls handler with it, and writes the handler's reply as the response.
(t *testing.T, handler func(req openAIRequest) (status int, body string, contentType string))
| 17 | // inbound request as an openAIRequest, calls handler with it, and |
| 18 | // writes the handler's reply as the response. |
| 19 | func fakeOpenAIUpstream(t *testing.T, handler func(req openAIRequest) (status int, body string, contentType string)) (*httptest.Server, *openAIRequest) { |
| 20 | t.Helper() |
| 21 | var captured openAIRequest |
| 22 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 23 | raw, _ := io.ReadAll(r.Body) |
| 24 | _ = json.Unmarshal(raw, &captured) |
| 25 | status, body, ct := handler(captured) |
| 26 | w.Header().Set("Content-Type", ct) |
| 27 | w.WriteHeader(status) |
| 28 | _, _ = io.WriteString(w, body) |
| 29 | })) |
| 30 | return srv, &captured |
| 31 | } |
| 32 | |
| 33 | func newTranslateCloudProxy(t *testing.T, upstreamURL string) *CloudProxy { |
| 34 | t.Helper() |
no test coverage detected