-
Notifications
You must be signed in to change notification settings - Fork 0
/
engines_test.go
34 lines (29 loc) · 915 Bytes
/
engines_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package openai_test
import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
. "github.com/lysunagopher/go-openai"
"github.com/lysunagopher/go-openai/internal/test"
"github.com/lysunagopher/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")
}