forked from tj/go-dropy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_test.go
75 lines (53 loc) · 1.26 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
65
66
67
68
69
70
71
72
73
74
75
package dropy
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFile_Open(t *testing.T) {
t.Parallel()
c := client()
f := c.Open("/hello.txt")
b, err := ioutil.ReadAll(f)
assert.NoError(t, err)
assert.Equal(t, "world", string(b))
}
func TestFile_Close(t *testing.T) {
t.Parallel()
c := client()
f := c.Open("/hello.txt")
assert.NoError(t, f.Close())
}
func TestFile_Close_inval(t *testing.T) {
t.Parallel()
c := client()
f := c.Open("/hello.txt")
assert.NoError(t, f.Close())
assert.EqualError(t, f.Close(), "close /hello.txt: invalid argument")
}
func TestFile_Read(t *testing.T) {
t.Parallel()
c := client()
f := c.Open("/hello.txt")
b := make([]byte, 5)
n, err := f.Read(b)
assert.Equal(t, 5, n)
assert.EqualError(t, err, "EOF")
assert.Equal(t, "world", string(b))
assert.NoError(t, f.Close())
}
func TestFile_Write(t *testing.T) {
t.Parallel()
c := client()
f := c.Open("/hello-world-1.txt")
_, err := f.Write([]byte("Hello"))
assert.NoError(t, err)
_, err = f.Write([]byte(" Wor"))
assert.NoError(t, err)
_, err = f.Write([]byte("ld"))
assert.NoError(t, err)
assert.NoError(t, f.Close())
b, err := c.Read("/hello-world-1.txt")
assert.NoError(t, err)
assert.Equal(t, "Hello World", string(b))
}