package llm import ( "context" "net/http" "net/http/httptest" "testing" ) func TestListModels(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/v1/models" { t.Fatalf("unexpected path: %s", r.URL.Path) } if got := r.Header.Get("Authorization"); got != "Bearer test-key" { t.Fatalf("unexpected auth header: %q", got) } w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`{"data":[{"id":"gpt-4o-mini"},{"id":"gpt-4o"},{"id":""}]}`)) })) defer srv.Close() client := NewClient() models, err := client.ListModels(context.Background(), Provider{ BaseURL: srv.URL + "/v1", APIKey: "test-key", }) if err != nil { t.Fatalf("ListModels: %v", err) } if len(models) != 2 || models[0] != "gpt-4o-mini" || models[1] != "gpt-4o" { t.Fatalf("unexpected models: %#v", models) } } func TestListModelsRequiresBaseURL(t *testing.T) { client := NewClient() _, err := client.ListModels(context.Background(), Provider{}) if err == nil { t.Fatal("expected error for empty base_url") } }