-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
api_upload_test.go
60 lines (53 loc) · 1.26 KB
/
api_upload_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
package lark
import (
"image/jpeg"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUploadImage(t *testing.T) {
resp, err := bot.UploadImage("./fixtures/test.jpg")
if assert.NoError(t, err) {
assert.Zero(t, resp.Code)
t.Log(resp.Data.ImageKey)
assert.NotEmpty(t, resp.Data.ImageKey)
}
}
func TestUploadImageObject(t *testing.T) {
file, _ := os.Open("./fixtures/test.jpg")
img, _ := jpeg.Decode(file)
resp, err := bot.UploadImageObject(img)
if assert.NoError(t, err) {
assert.Zero(t, resp.Code)
t.Log(resp.Data.ImageKey)
assert.NotEmpty(t, resp.Data.ImageKey)
}
}
func TestUploadFile(t *testing.T) {
resp, err := bot.UploadFile(UploadFileRequest{
FileType: "pdf",
FileName: "hello.pdf",
Path: "./fixtures/test.pdf",
})
if assert.NoError(t, err) {
assert.Zero(t, resp.Code)
t.Log(resp.Data.FileKey)
assert.NotEmpty(t, resp.Data.FileKey)
}
}
func TestUploadFile_Binary(t *testing.T) {
resp, err := bot.UploadFile(UploadFileRequest{
FileType: "stream",
FileName: "test-data.csv",
Reader: strings.NewReader(`Name,Age,Location
Foo,25,Sleman
Bar,23,Sidoarjo
Baz,27,Bantul`),
})
if assert.NoError(t, err) {
assert.Zero(t, resp.Code)
t.Log(resp.Data.FileKey)
assert.NotEmpty(t, resp.Data.FileKey)
}
}