Skip to content

Commit ef47d31

Browse files
committed
add a test for openai.GetEngine
1 parent 7eb94ba commit ef47d31

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

engines_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package openai_test
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
"testing"
9+
10+
. "github.com/sashabaranov/go-openai"
11+
"github.com/sashabaranov/go-openai/internal/test"
12+
"github.com/sashabaranov/go-openai/internal/test/checks"
13+
)
14+
15+
// TestGetEngine Tests the retrieve engine endpoint of the API using the mocked server.
16+
func TestGetEngine(t *testing.T) {
17+
server := test.NewTestServer()
18+
server.RegisterHandler("/v1/engines/text-davinci-003", func(w http.ResponseWriter, r *http.Request) {
19+
resBytes, _ := json.Marshal(Engine{})
20+
fmt.Fprintln(w, string(resBytes))
21+
22+
})
23+
// create the test server
24+
ts := server.OpenAITestServer()
25+
ts.Start()
26+
defer ts.Close()
27+
28+
config := DefaultConfig(test.GetTestToken())
29+
config.BaseURL = ts.URL + "/v1"
30+
client := NewClientWithConfig(config)
31+
ctx := context.Background()
32+
33+
_, err := client.GetEngine(ctx, "text-davinci-003")
34+
checks.NoError(t, err, "GetEngine error")
35+
}

0 commit comments

Comments
 (0)