-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles_test.go
60 lines (54 loc) · 1.37 KB
/
files_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 arvanvod_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUploadFile(t *testing.T) {
client := getClient()
filename := "sample.mp4"
path := filepath.Join("samples", filename)
file, err := os.Open(path)
if assert.NoError(t, err) {
data, err := ioutil.ReadAll(file)
assert.Equal(t, nil, err)
length := int64(len(data))
channel := "19fee3b0-a850-4fa6-bfb0-9563a19c811f"
meta := map[string]string{
"filename": filename,
"filetype": "video/mp4",
}
location, err := client.NewFileUpload(context.Background(), channel, int64(length), meta)
if assert.NoError(t, err) {
assert.NotEmpty(t, location)
ss := strings.Split(location, "/")
fileId := ss[len(ss)-1]
step := int64(1000000)
for {
offset, len, err := client.GetUploadOffset(context.Background(), channel, fileId)
assert.Equal(t, nil, err)
assert.Equal(t, length, len)
if offset == len || err != nil {
break
}
end := len
if offset+step < len {
end = offset + step
}
bytes := data[offset:end]
offset, err = client.UploadFileBytes(context.Background(), channel, fileId, bytes)
assert.Equal(t, nil, err)
fmt.Printf("\n len: %d, offset: %d", len, offset)
if offset == len || err != nil {
break
}
}
fmt.Printf("\n finished!")
}
}
}