summaryrefslogtreecommitdiff
path: root/internal/llm/ollama_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-11 00:21:50 +0300
committerPaul Buetow <paul@buetow.org>2026-06-11 00:21:50 +0300
commit2b2f4110da53a03742faff89cdec17c55e091a90 (patch)
treeb0c355f2470dbf984f373e0dcc45f12d00960a98 /internal/llm/ollama_test.go
parent1f3ae20a9830fd776f6ef3c11b4c198154b8205f (diff)
llm: return concrete client types from provider constructors
Follow the Go idiom "return concrete types, accept interfaces": the provider constructors newOpenAI, newAnthropic, newOpenRouter, newOllama and their *WithTimeout variants now return their concrete *Client value types instead of the Client interface. The provider factories registered in the registry still return Client, so NewFromConfig and the registry keep working unchanged. Updated comments to explain the reasoning, dropped the now-redundant type assertions in tests, and switched the anthropic Streamer-capability tests to assert via an explicit Client interface value. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/llm/ollama_test.go')
-rw-r--r--internal/llm/ollama_test.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/internal/llm/ollama_test.go b/internal/llm/ollama_test.go
index 2216e21..e319617 100644
--- a/internal/llm/ollama_test.go
+++ b/internal/llm/ollama_test.go
@@ -49,7 +49,7 @@ func TestBuildOllamaRequest_TempOverride(t *testing.T) {
}
func TestOllama_NameAndModel(t *testing.T) {
- c := newOllama("http://x", "model-x", nil, "").(ollamaClient)
+ c := newOllama("http://x", "model-x", nil, "")
if c.Name() != "ollama" {
t.Fatalf("name: %q", c.Name())
}
@@ -71,7 +71,7 @@ func TestOllamaChat_NoAuthHeaderWhenKeyEmpty(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"message": map[string]string{"role": "assistant", "content": "ok"}, "done": true})
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", nil, "").(ollamaClient)
+ c := newOllama(ts.URL, "m", nil, "")
c.httpClient = ts.Client()
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}}); err != nil {
t.Fatalf("unexpected: %v", err)
@@ -95,7 +95,7 @@ func TestOllamaChat_AuthHeaderWhenKeySet(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"message": map[string]string{"role": "assistant", "content": "ok"}, "done": true})
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", f64p(0.1), key).(ollamaClient)
+ c := newOllama(ts.URL, "m", f64p(0.1), key)
c.httpClient = ts.Client()
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}}); err != nil {
t.Fatalf("unexpected: %v", err)
@@ -110,7 +110,7 @@ func TestOllamaChat_AuthHeaderWhenKeySet(t *testing.T) {
_, _ = w.Write([]byte(`{"message":{"role":"assistant","content":"ok"},"done":true}`))
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", nil, key).(ollamaClient)
+ c := newOllama(ts.URL, "m", nil, key)
c.httpClient = ts.Client()
if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "hi"}}, func(string) {}); err != nil {
t.Fatalf("unexpected: %v", err)
@@ -130,7 +130,7 @@ func TestOllamaChat_Success(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"message": map[string]string{"role": "assistant", "content": "Hello"}, "done": true})
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", f64p(0.1), "").(ollamaClient)
+ c := newOllama(ts.URL, "m", f64p(0.1), "")
c.httpClient = ts.Client()
out, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}})
if err != nil {
@@ -149,7 +149,7 @@ func TestOllamaChat_EmptyContent(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"message": map[string]string{"role": "assistant", "content": ""}, "done": true})
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", nil, "").(ollamaClient)
+ c := newOllama(ts.URL, "m", nil, "")
c.httpClient = ts.Client()
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "x"}}); err == nil {
t.Fatalf("expected error for empty content")
@@ -166,7 +166,7 @@ func TestOllamaChat_Non2xx(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"error": "bad"})
}))
defer ts1.Close()
- c1 := newOllama(ts1.URL, "m", nil, "").(ollamaClient)
+ c1 := newOllama(ts1.URL, "m", nil, "")
c1.httpClient = ts1.Client()
if _, err := c1.Chat(context.Background(), []Message{{Role: "user", Content: "x"}}); err == nil {
t.Fatalf("expected error for 400 with api body")
@@ -177,7 +177,7 @@ func TestOllamaChat_Non2xx(t *testing.T) {
_, _ = w.Write([]byte("{}"))
}))
defer ts2.Close()
- c2 := newOllama(ts2.URL, "m", nil, "").(ollamaClient)
+ c2 := newOllama(ts2.URL, "m", nil, "")
c2.httpClient = ts2.Client()
if _, err := c2.Chat(context.Background(), []Message{{Role: "user", Content: "x"}}); err == nil {
t.Fatalf("expected error for 500")
@@ -189,7 +189,7 @@ type rtFunc func(*http.Request) (*http.Response, error)
func (f rtFunc) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
func TestOllamaChat_HTTPError(t *testing.T) {
- c := newOllama("http://127.0.0.1:0", "m", nil, "").(ollamaClient)
+ c := newOllama("http://127.0.0.1:0", "m", nil, "")
c.httpClient = &http.Client{Transport: rtFunc(func(*http.Request) (*http.Response, error) { return nil, fmt.Errorf("boom") })}
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "x"}}); err == nil {
t.Fatalf("expected http error path")
@@ -204,7 +204,7 @@ func TestOllamaChat_DecodeError(t *testing.T) {
_, _ = w.Write([]byte("{bad json}"))
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", nil, "").(ollamaClient)
+ c := newOllama(ts.URL, "m", nil, "")
c.httpClient = ts.Client()
if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "x"}}); err == nil {
t.Fatalf("expected decode error")
@@ -229,7 +229,7 @@ func TestOllamaChatStream_Success(t *testing.T) {
_, _ = w.Write([]byte(`{"message":{"role":"assistant","content":"!"},"done":true}`))
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", nil, "").(ollamaClient)
+ c := newOllama(ts.URL, "m", nil, "")
c.httpClient = ts.Client()
var got strings.Builder
if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "x"}}, func(s string) { got.WriteString(s) }); err != nil {
@@ -248,7 +248,7 @@ func TestOllamaChatStream_ErrorEvent(t *testing.T) {
_ = json.NewEncoder(w).Encode(map[string]any{"error": "oops"})
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", nil, "").(ollamaClient)
+ c := newOllama(ts.URL, "m", nil, "")
c.httpClient = ts.Client()
if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "x"}}, func(string) {}); err == nil {
t.Fatalf("expected stream error")
@@ -263,7 +263,7 @@ func TestOllamaChatStream_DecodeError(t *testing.T) {
_, _ = w.Write([]byte("{not json}"))
}))
defer ts.Close()
- c := newOllama(ts.URL, "m", nil, "").(ollamaClient)
+ c := newOllama(ts.URL, "m", nil, "")
c.httpClient = ts.Client()
if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "x"}}, func(string) {}); err == nil {
t.Fatalf("expected decode error")