Skip to content

Commit

Permalink
add a test for openai.GetEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatanabe committed May 30, 2023
1 parent 7eb94ba commit 8e9c035
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions engines_test.go
Original file line number Diff line number Diff line change
@@ -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))

Check failure on line 21 in engines_test.go

View workflow job for this annotation

GitHub Actions / Sanity check

unnecessary trailing newline (whitespace)
})
// 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")
}

0 comments on commit 8e9c035

Please sign in to comment.