(t *testing.T)
| 154 | } |
| 155 | |
| 156 | func 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 | |
| 186 | func testConfigWithFileKB(t *testing.T) *config.Config { |
| 187 | t.Helper() |
nothing calls this directly
no test coverage detected