-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_files_test.go
123 lines (112 loc) · 4.42 KB
/
client_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package koofrclient_test
import (
"bytes"
"io/ioutil"
"strings"
koofrclient "github.com/koofr/go-koofrclient"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ClientFiles", func() {
BeforeEach(func() {
client.FilesDelete(defaultMountId, rootPath)
parts := strings.Split(rootPath, "/")
created := "/"
for _, part := range parts {
if part != "" {
client.FilesDelete(defaultMountId, created+"/"+part)
err := client.FilesNewFolder(defaultMountId, created, part)
Expect(err).NotTo(HaveOccurred())
created += "/" + part
}
}
})
It("should get file info", func() {
info, err := client.FilesInfo(defaultMountId, rootPath)
Expect(err).NotTo(HaveOccurred())
parts := strings.Split(rootPath, "/")
expected := parts[len(parts)-1]
Expect(info.Name).To(Equal(expected))
})
It("should list files", func() {
files, err := client.FilesList(defaultMountId, rootPath)
Expect(err).NotTo(HaveOccurred())
Expect(files).To(HaveLen(0))
})
It("should get files tree", func() {
tree, err := client.FilesTree(defaultMountId, rootPath)
Expect(err).NotTo(HaveOccurred())
parts := strings.Split(rootPath, "/")
expected := parts[len(parts)-1]
Expect(tree.Name).To(Equal(expected))
Expect(tree.Children).To(HaveLen(0))
})
It("should create new folder and delete it", func() {
err := client.FilesNewFolder(defaultMountId, rootPath, "dir")
Expect(err).NotTo(HaveOccurred())
err = client.FilesDelete(defaultMountId, rootPath+"/dir")
Expect(err).NotTo(HaveOccurred())
_, err = client.FilesInfo(defaultMountId, rootPath+"/dir")
Expect(err).To(HaveOccurred())
})
It("should copy a folder", func() {
err := client.FilesNewFolder(defaultMountId, rootPath, "dir")
Expect(err).NotTo(HaveOccurred())
err = client.FilesCopy(defaultMountId, rootPath+"/dir", defaultMountId, rootPath+"/dircopy")
Expect(err).NotTo(HaveOccurred())
_, err = client.FilesInfo(defaultMountId, rootPath+"/dir")
Expect(err).NotTo(HaveOccurred())
_, err = client.FilesInfo(defaultMountId, rootPath+"/dircopy")
Expect(err).NotTo(HaveOccurred())
})
It("should move a folder", func() {
err := client.FilesNewFolder(defaultMountId, rootPath, "dir")
Expect(err).NotTo(HaveOccurred())
err = client.FilesMove(defaultMountId, rootPath+"/dir", defaultMountId, rootPath+"/dirmoved")
Expect(err).NotTo(HaveOccurred())
_, err = client.FilesInfo(defaultMountId, rootPath+"/dir")
Expect(err).To(HaveOccurred())
_, err = client.FilesInfo(defaultMountId, rootPath+"/dirmoved")
Expect(err).NotTo(HaveOccurred())
})
It("should put file, get it and delete it", func() {
newName, err := client.FilesPut(defaultMountId, rootPath, "file.txt", bytes.NewReader([]byte("content")))
Expect(err).NotTo(HaveOccurred())
Expect(newName).To(Equal("file.txt"))
reader, err := client.FilesGet(defaultMountId, rootPath+"/file.txt")
Expect(err).NotTo(HaveOccurred())
content, err := ioutil.ReadAll(reader)
Expect(err).NotTo(HaveOccurred())
Expect(content).To(Equal([]byte("content")))
reader, err = client.FilesGetRange(defaultMountId, rootPath+"/file.txt", &koofrclient.FileSpan{Start: 2, End: 3})
Expect(err).NotTo(HaveOccurred())
content, err = ioutil.ReadAll(reader)
Expect(err).NotTo(HaveOccurred())
Expect(content).To(Equal([]byte("nt")))
err = client.FilesDelete(defaultMountId, rootPath+"/file.txt")
Expect(err).NotTo(HaveOccurred())
})
It("should put a file and set its modified time", func() {
mtime := int64(1562663291000)
putOptions := koofrclient.PutOptions{
SetModified: &mtime,
}
_, err := client.FilesPutWithOptions(defaultMountId, rootPath, "file.txt", bytes.NewReader([]byte("content")), &putOptions)
Expect(err).NotTo(HaveOccurred())
reader, err := client.FilesGet(defaultMountId, rootPath+"/file.txt")
Expect(err).NotTo(HaveOccurred())
content, err := ioutil.ReadAll(reader)
Expect(err).NotTo(HaveOccurred())
Expect(content).To(Equal([]byte("content")))
reader, err = client.FilesGetRange(defaultMountId, rootPath+"/file.txt", &koofrclient.FileSpan{Start: 2, End: 3})
Expect(err).NotTo(HaveOccurred())
content, err = ioutil.ReadAll(reader)
Expect(err).NotTo(HaveOccurred())
Expect(content).To(Equal([]byte("nt")))
info, err := client.FilesInfo(defaultMountId, rootPath+"/file.txt")
Expect(err).NotTo(HaveOccurred())
Expect(info.Modified).To(Equal(int64(1562663291000)))
err = client.FilesDelete(defaultMountId, rootPath+"/file.txt")
Expect(err).NotTo(HaveOccurred())
})
})