From d0d61a5d7758634948da66cbb365a7b6f5c09c76 Mon Sep 17 00:00:00 2001 From: Dinh Nguyen Date: Thu, 7 May 2026 14:23:12 +0700 Subject: [PATCH] Update ollama api test --- .../httpapi/ollama/handler_routes_test.go | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/internal/httpapi/ollama/handler_routes_test.go b/internal/httpapi/ollama/handler_routes_test.go index 54cee70..43ddfa9 100644 --- a/internal/httpapi/ollama/handler_routes_test.go +++ b/internal/httpapi/ollama/handler_routes_test.go @@ -1,22 +1,30 @@ package ollama import ( - "net/http" - "net/http/httptest" - "testing" - "strings" - "github.com/go-chi/chi/v5" + "net/http" + "net/http/httptest" + "testing" + "strings" + "github.com/go-chi/chi/v5" ) type ollamaTestSurface struct { - Store ConfigReader - handler *Handler + Store ConfigReader + handler *Handler } +func (h *ollamaTestSurface) apiHandler() *Handler { + if h.handler == nil { + h.handler = &Handler{Store: h.Store} + } + return h.handler +} + + func registerOllamaTestRoutes(r chi.Router, h *ollamaTestSurface) { - r.Get("/api/version", h.handler().GetVersion) - r.Get("/api/tags", h.handler().ListOllamaModels) - r.Post("/api/show", h.handler().GetOllamaModel) + r.Get("/api/version", h.apiHandler().GetVersion) + r.Get("/api/tags", h.apiHandler().ListOllamaModels) + r.Post("/api/show", h.apiHandler().GetOllamaModel) } @@ -74,7 +82,7 @@ func TestGetOllamaModelRoute(t *testing.T) { }) t.Run("direct_expert", func(t *testing.T) { - body := `{"model":"models/deepseek-v4-pro"}` + body := `{"model":"deepseek-v4-pro"}` req := httptest.NewRequest(http.MethodPost, "/api/show", strings.NewReader(body)) req.Header.Set("Content-Type", "application/json") rec := httptest.NewRecorder()