MCPcopy Create free account
hub / github.com/InferCore/InferCore / TestInfer_OKWithInfercoreAPIKeyHeader

Function TestInfer_OKWithInfercoreAPIKeyHeader

internal/server/server_test.go:156–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

154}
155
156func TestInfer_OKWithInfercoreAPIKeyHeader(t *testing.T) {
157 cfg := testConfig(100, true)
158 cfg.Server.InfercoreAPIKey = "unit-test-secret"
159 srv := New(cfg)
160 ts := httptest.NewServer(srv.Routes())
161 defer ts.Close()
162
163 payload, _ := json.Marshal(map[string]any{
164 "tenant_id": "team-a",
165 "task_type": "simple",
166 "input": map[string]any{"text": "hello"},
167 "options": map[string]any{"stream": false, "max_tokens": 128},
168 })
169 req, err := http.NewRequest(http.MethodPost, ts.URL+"/infer", bytes.NewReader(payload))
170 if err != nil {
171 t.Fatal(err)
172 }
173 req.Header.Set("Content-Type", "application/json")
174 req.Header.Set("X-InferCore-Api-Key", "unit-test-secret")
175 resp, err := http.DefaultClient.Do(req)
176 if err != nil {
177 t.Fatal(err)
178 }
179 defer resp.Body.Close()
180 if resp.StatusCode != http.StatusOK {
181 body, _ := io.ReadAll(resp.Body)
182 t.Fatalf("expected 200, got %d %s", resp.StatusCode, string(body))
183 }
184}
185
186func testConfigWithFileKB(t *testing.T) *config.Config {
187 t.Helper()

Callers

nothing calls this directly

Calls 4

RoutesMethod · 0.80
testConfigFunction · 0.70
NewFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected