MCPcopy
hub / github.com/mudler/LocalAI / fakeOpenAIUpstream

Function fakeOpenAIUpstream

backend/go/cloud-proxy/provider_openai_test.go:19–31  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

17// inbound request as an openAIRequest, calls handler with it, and
18// writes the handler's reply as the response.
19func 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
33func newTranslateCloudProxy(t *testing.T, upstreamURL string) *CloudProxy {
34 t.Helper()

Calls 4

HeaderMethod · 0.80
SetMethod · 0.65
handlerFunction · 0.50
WriteHeaderMethod · 0.45

Tested by

no test coverage detected