(t *testing.T)
| 170 | } |
| 171 | |
| 172 | func TestAdapterConformance_Gemini(t *testing.T) { |
| 173 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 174 | if r.Header.Get("x-goog-api-key") == "" { |
| 175 | w.WriteHeader(http.StatusUnauthorized) |
| 176 | return |
| 177 | } |
| 178 | switch { |
| 179 | case r.Method == http.MethodGet && r.URL.Path == "/v1beta/models": |
| 180 | w.WriteHeader(http.StatusOK) |
| 181 | case r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, ":generateContent"): |
| 182 | w.Header().Set("Content-Type", "application/json") |
| 183 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 184 | "candidates": []map[string]any{ |
| 185 | { |
| 186 | "content": map[string]any{ |
| 187 | "parts": []map[string]any{{"text": "hello from gemini"}}, |
| 188 | }, |
| 189 | }, |
| 190 | }, |
| 191 | }) |
| 192 | default: |
| 193 | http.NotFound(w, r) |
| 194 | } |
| 195 | })) |
| 196 | defer srv.Close() |
| 197 | |
| 198 | adapter := gemini.New(config.BackendConfig{ |
| 199 | Name: "gem-b", |
| 200 | Type: "gemini", |
| 201 | Endpoint: srv.URL, |
| 202 | TimeoutMS: 200, |
| 203 | APIKey: "test-key", |
| 204 | DefaultModel: "gemini-2.0-flash", |
| 205 | Capabilities: []string{"chat"}, |
| 206 | Cost: config.CostConfig{Unit: 2}, |
| 207 | }) |
| 208 | assertAdapterConformance(t, adapter) |
| 209 | } |
| 210 | |
| 211 | func assertAdapterConformance(t *testing.T, adapter interfaces.BackendAdapter) { |
| 212 | t.Helper() |
nothing calls this directly
no test coverage detected