From ef47d3113d52beaa4fc0ef611771923d4d3afb06 Mon Sep 17 00:00:00 2001 From: vvatanabe Date: Tue, 30 May 2023 09:54:51 +0900 Subject: [PATCH] add a test for openai.GetEngine --- engines_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 engines_test.go diff --git a/engines_test.go b/engines_test.go new file mode 100644 index 000000000..589819d42 --- /dev/null +++ b/engines_test.go @@ -0,0 +1,35 @@ +package openai_test + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "testing" + + . "github.com/sashabaranov/go-openai" + "github.com/sashabaranov/go-openai/internal/test" + "github.com/sashabaranov/go-openai/internal/test/checks" +) + +// TestGetEngine Tests the retrieve engine endpoint of the API using the mocked server. +func TestGetEngine(t *testing.T) { + server := test.NewTestServer() + server.RegisterHandler("/v1/engines/text-davinci-003", func(w http.ResponseWriter, r *http.Request) { + resBytes, _ := json.Marshal(Engine{}) + fmt.Fprintln(w, string(resBytes)) + + }) + // create the test server + ts := server.OpenAITestServer() + ts.Start() + defer ts.Close() + + config := DefaultConfig(test.GetTestToken()) + config.BaseURL = ts.URL + "/v1" + client := NewClientWithConfig(config) + ctx := context.Background() + + _, err := client.GetEngine(ctx, "text-davinci-003") + checks.NoError(t, err, "GetEngine error") +}