-
Notifications
You must be signed in to change notification settings - Fork 342
/
remove_test.go
118 lines (87 loc) · 2.85 KB
/
remove_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
package hdfs
import (
"os"
"syscall"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRemoveFile(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/todelete")
mkdirp(t, "/_test/todelete")
touch(t, "/_test/todelete/deleteme")
err := client.Remove("/_test/todelete/deleteme")
require.NoError(t, err)
fi, err := client.Stat("/_test/todelete/deleteme")
assert.Nil(t, fi)
assertPathError(t, err, "stat", "/_test/todelete/deleteme", os.ErrNotExist)
}
func TestRemoveEmptyDir(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/todelete")
mkdirp(t, "/_test/todelete")
err := client.Remove("/_test/todelete")
require.NoError(t, err)
fi, err := client.Stat("/_test/todelete")
assert.Nil(t, fi)
assertPathError(t, err, "stat", "/_test/todelete", os.ErrNotExist)
}
func TestRemoveNonEmptyDir(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/todelete")
mkdirp(t, "/_test/todelete")
touch(t, "/_test/todelete/dummy")
err := client.Remove("/_test/todelete")
assertPathError(t, err, "remove", "/_test/todelete", syscall.ENOTEMPTY)
fi, err := client.Stat("/_test/todelete/dummy")
require.NoError(t, err)
assert.NotNil(t, fi)
}
func TestRemoveNonexistent(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/nonexistent")
err := client.Remove("/_test/nonexistent")
assertPathError(t, err, "remove", "/_test/nonexistent", os.ErrNotExist)
}
func TestRemoveWithoutPermission(t *testing.T) {
client := getClientForUser(t, "gohdfs2")
mkdirp(t, "/_test/accessdenied")
touch(t, "/_test/accessdenied/foo")
err := client.Remove("/_test/accessdenied/foo")
assertPathError(t, err, "remove", "/_test/accessdenied/foo", os.ErrPermission)
}
func TestRemoveAllEmptyDir(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/todelete")
mkdirp(t, "/_test/todelete")
err := client.RemoveAll("/_test/todelete")
require.NoError(t, err)
fi, err := client.Stat("/_test/todelete")
assert.Nil(t, fi)
assertPathError(t, err, "stat", "/_test/todelete", os.ErrNotExist)
}
func TestRemoveAllNonEmptyDir(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/todelete")
mkdirp(t, "/_test/todelete")
touch(t, "/_test/todelete/dummy")
err := client.RemoveAll("/_test/todelete")
require.NoError(t, err)
fi, err := client.Stat("/_test/todelete")
assert.Nil(t, fi)
assertPathError(t, err, "stat", "/_test/todelete", os.ErrNotExist)
}
func TestRemoveAllNonexistent(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/nonexistent")
err := client.RemoveAll("/_test/nonexistent")
require.NoError(t, err)
}
func TestRemoveAllWithoutPermission(t *testing.T) {
client := getClientForUser(t, "gohdfs2")
mkdirp(t, "/_test/accessdenied")
touch(t, "/_test/accessdenied/foo")
err := client.RemoveAll("/_test/accessdenied/foo")
assertPathError(t, err, "remove", "/_test/accessdenied/foo", os.ErrPermission)
}