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 ef47d31
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))

})
// 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 ef47d31

Please sign in to comment.