-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcreate_test.go
62 lines (52 loc) · 1.4 KB
/
create_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
package files_test
import (
"log"
"net/http"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/yitsushi/go-misskey"
"github.com/yitsushi/go-misskey/core"
"github.com/yitsushi/go-misskey/services/drive/files"
"github.com/yitsushi/go-misskey/test"
)
func TestService_Create(t *testing.T) {
client := test.MakeMockClient(test.SimpleMockOptions{
Endpoint: "/api/drive/files/create",
RequestData: &files.CreateRequest{},
ResponseFile: "file.json",
StatusCode: http.StatusOK,
Type: test.IgnoreMockType,
})
response, err := client.Drive().File().Create(files.CreateRequest{
Name: "file-name",
FolderID: "fancy-folder-id",
IsSensitive: false,
Force: false,
Content: []byte("my content"),
})
if !assert.NoError(t, err) {
return
}
assert.Equal(t, "file-name", core.StringValue(response.Name))
}
func ExampleService_Create() {
client, _ := misskey.NewClientWithOptions(misskey.WithSimpleConfig("https://slippy.xyz", os.Getenv("MISSKEY_TOKEN")))
fileContent := []byte{}
file, err := client.Drive().File().Create(files.CreateRequest{
FolderID: "",
Name: "this is the name",
IsSensitive: false,
Force: false,
Content: fileContent,
})
if err != nil {
log.Printf("[Drive/File/Create] %s", err)
return
}
log.Printf(
"[Drive/File/Create] %s file uploaded. (%s)",
core.StringValue(file.Name),
file.ID,
)
}