diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-04 14:35:56 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-04 14:35:56 +0300 |
| commit | 48fac4b473e2564e2e82dad36668277f1071ddd0 (patch) | |
| tree | 3e4c75e66a32822d35be6ee947a31a61c54261a2 /internal/llm/openai_http_test.go | |
| parent | d68e5b3b188585fe234d0ce295ec7f054c8bad5f (diff) | |
tests(llm): add OpenAI and Copilot HTTP tests (success + token/error paths); llm coverage ~61%
Diffstat (limited to 'internal/llm/openai_http_test.go')
| -rw-r--r-- | internal/llm/openai_http_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/llm/openai_http_test.go b/internal/llm/openai_http_test.go new file mode 100644 index 0000000..4989067 --- /dev/null +++ b/internal/llm/openai_http_test.go @@ -0,0 +1,27 @@ +package llm + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" +) + +func TestOpenAI_Chat_Success(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/chat/completions" { t.Fatalf("unexpected path: %s", r.URL.Path) } + _ = json.NewEncoder(w).Encode(map[string]any{"choices": []map[string]any{{"index":0, "message": map[string]string{"role":"assistant","content":"OK"}}}}) + })) + defer srv.Close() + c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient) + c.httpClient = srv.Client() + out, err := c.Chat(context.Background(), []Message{{Role:"user", Content:"hi"}}) + if err != nil || out != "OK" { t.Fatalf("openai chat: %v %q", err, out) } +} + +func TestOpenAI_Chat_MissingKey(t *testing.T) { + c := newOpenAI("http://x", "g", "", f64p(0.2)).(openAIClient) + if _, err := c.Chat(context.Background(), []Message{{Role:"user", Content:"hi"}}); err == nil { t.Fatalf("expected error for missing key") } +} + |
