forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename_test.go
66 lines (47 loc) · 1.7 KB
/
rename_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
package hdfs
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestRename(t *testing.T) {
client := getClient(t)
touch(t, "/_test/tomove")
baleet(t, "/_test/tomovedest")
err := client.Rename("/_test/tomove", "/_test/tomovedest")
assert.Nil(t, err)
fi, err := client.Stat("/_test/tomove")
assert.Nil(t, fi)
assertPathError(t, err, "stat", "/_test/tomove", os.ErrNotExist)
fi, err = client.Stat("/_test/tomovedest")
assert.Nil(t, err)
}
func TestRenameSrcNotExistent(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/nonexistent")
baleet(t, "/_test/nonexistent2")
err := client.Rename("/_test/nonexistent", "/_test/nonexistent2")
assertPathError(t, err, "rename", "/_test/nonexistent", os.ErrNotExist)
}
func TestRenameDestExists(t *testing.T) {
client := getClient(t)
touch(t, "/_test/tomove2")
touch(t, "/_test/tomovedest2")
err := client.Rename("/_test/tomove2", "/_test/tomovedest2")
assertPathError(t, err, "rename", "/_test/tomovedest2", os.ErrExist)
}
func TestRenameWithoutPermissionForSrc(t *testing.T) {
otherClient := getClientForUser(t, "other")
mkdirp(t, "/_test/accessdenied")
touch(t, "/_test/accessdenied/foo")
err := otherClient.Rename("/_test/accessdenied/foo", "/_test/tomovedest3")
assertPathError(t, err, "rename", "/_test/accessdenied/foo", os.ErrPermission)
}
func TestRenameWithoutPermissionForDest(t *testing.T) {
otherClient := getClientForUser(t, "other")
baleet(t, "/_test/ownedbyother")
err := otherClient.CreateEmptyFile("/_test/ownedbyother")
assert.Nil(t, err)
err = otherClient.Rename("/_test/ownedbyother", "/_test/accessdenied/tomovedest4")
assertPathError(t, err, "rename", "/_test/accessdenied/tomovedest4", os.ErrPermission)
}