From a25739dfde760e6e01625faf4cfc38b89d262558 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Thu, 13 Feb 2025 19:43:56 +0100 Subject: [PATCH] e2e: add models test using the openai client (#338) **Commit Message** e2e: add test for the models endpoint using the openai client **Related Issues/PRs (if applicable)** Related to https://github.com/envoyproxy/ai-gateway/pull/325 **Special notes for reviewers (if applicable)** N/A --------- Signed-off-by: Ignasi Barrera --- tests/extproc/real_providers_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/extproc/real_providers_test.go b/tests/extproc/real_providers_test.go index b4e1b386..32eae0c2 100644 --- a/tests/extproc/real_providers_test.go +++ b/tests/extproc/real_providers_test.go @@ -19,6 +19,7 @@ import ( "github.com/openai/openai-go" "github.com/openai/openai-go/option" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/envoyproxy/ai-gateway/filterapi" @@ -230,6 +231,29 @@ func TestWithRealProviders(t *testing.T) { return returnsToolCall }, 30*time.Second, 2*time.Second) }) + + // Models are served by the extproc filter as a direct response so this can run even if the + // real credentials are not present. + // We don't need to run it on a concrete backend, as it will not route anywhere. + t.Run("list-models", func(t *testing.T) { + client := openai.NewClient(option.WithBaseURL(listenerAddress + "/v1/")) + + var models []string + + require.EventuallyWithT(t, func(c *assert.CollectT) { + it := client.Models.ListAutoPaging(t.Context()) + for it.Next() { + models = append(models, it.Current().ID) + } + assert.NoError(c, it.Err()) + }, 30*time.Second, 2*time.Second) + + require.Equal(t, []string{ + "gpt-4o-mini", + "us.meta.llama3-2-1b-instruct-v1:0", + "us.anthropic.claude-3-5-sonnet-20240620-v1:0", + }, models) + }) } // realProvidersTestCase is a base test case for the real providers, which is mainly for the centralization of the