summaryrefslogtreecommitdiff
path: root/internal/llm/openai_http_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-04 16:16:23 +0300
committerPaul Buetow <paul@buetow.org>2025-09-04 16:16:23 +0300
commit2a6ff853c20e6c1c780c69affdadacda2db202b6 (patch)
treeb987323524c026dd86280e28cb9f696fc3fade5b /internal/llm/openai_http_test.go
parent09b33e65d92f5fb5b907e49c3d27584615cf2b83 (diff)
tests: expand negative SSE and table-driven coverage; add docs/testing.md; use shared fixtures
Diffstat (limited to 'internal/llm/openai_http_test.go')
-rw-r--r--internal/llm/openai_http_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/llm/openai_http_test.go b/internal/llm/openai_http_test.go
index 78830ba..45f0c99 100644
--- a/internal/llm/openai_http_test.go
+++ b/internal/llm/openai_http_test.go
@@ -63,6 +63,20 @@ func TestOpenAI_ChatStream_SSE_ErrorChunk(t *testing.T) {
}
}
+func TestOpenAI_Chat_DecodeError_StatusOK(t *testing.T) {
+ // Return status 200 but invalid JSON body; Chat should return an error
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(200)
+ io.WriteString(w, "{invalid")
+ }))
+ defer srv.Close()
+ c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient)
+ c.httpClient = srv.Client()
+ if _, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}}); err == nil {
+ t.Fatalf("expected decode error for invalid JSON body")
+ }
+}
+
func TestOpenAI_Chat_MultiChoiceAndErrorBody(t *testing.T) {
// Multi-choice success: return two choices with different finish reasons
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {