-
Notifications
You must be signed in to change notification settings - Fork 36
/
file_test.go
64 lines (54 loc) · 1.87 KB
/
file_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package openaigo
import (
"context"
"os"
"testing"
. "github.com/otiai10/mint"
)
func TestClient_UploadFile(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
_, err := client.UploadFile(nil, FileUploadRequestBody{})
Expect(t, err).Not().ToBe(nil)
f, _ := os.Open("./testdata/train.jsonl")
res, err := client.UploadFile(nil, FileUploadRequestBody{File: f})
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.FileUploadResponse")
}
func TestClient_ListFiles(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
res, err := client.ListFiles(nil)
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.FileListResponse")
}
func TestClient_RetrieveFileContent(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
res, err := client.RetrieveFileContent(context.TODO(), "abcdefg")
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("*http.bodyEOFSignal")
res.Close()
_, err = client.RetrieveFileContent(context.TODO(), "notfound")
Expect(t, err).Not().ToBe(nil)
}
func TestClient_RetrieveFile(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
res, err := client.RetrieveFile(nil, "abcdefg")
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.FileRetrieveResponse")
_, err = client.RetrieveFile(nil, "abc")
Expect(t, err).Not().ToBe(nil)
Expect(t, err.Error()).ToBe("openai API error: invalid_request_error: No such File object: abc (param: id, code: <nil>)")
_, err = client.RetrieveFile(nil, "zzz")
Expect(t, err).Not().ToBe(nil)
Expect(t, err.Error()).ToBe("failed to decode error body: invalid character '.' looking for beginning of object key string")
}
func TestClient_DeleteFile(t *testing.T) {
client := NewClient("")
client.BaseURL = mockserver.URL
res, err := client.DeleteFile(nil, "abcdefg")
Expect(t, err).ToBe(nil)
Expect(t, res).TypeOf("openaigo.FileDeleteResponse")
}