File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments