forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 5
/
readdir_test.go
93 lines (68 loc) · 2.16 KB
/
readdir_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
package hdfs
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReadDir(t *testing.T) {
client := getClient(t)
mkdirp(t, "/_test/fulldir")
mkdirp(t, "/_test/fulldir/dir")
touch(t, "/_test/fulldir/1")
touch(t, "/_test/fulldir/2")
touch(t, "/_test/fulldir/3")
res, err := client.ReadDir("/_test/fulldir")
require.NoError(t, err)
require.Equal(t, len(res), 4)
assert.EqualValues(t, "1", res[0].Name())
assert.False(t, res[0].IsDir())
assert.EqualValues(t, "2", res[1].Name())
assert.False(t, res[1].IsDir())
assert.EqualValues(t, "3", res[2].Name())
assert.False(t, res[2].IsDir())
assert.EqualValues(t, "dir", res[3].Name())
assert.True(t, res[3].IsDir())
}
func TestReadDirTrailingSlash(t *testing.T) {
client := getClient(t)
mkdirp(t, "/_test/fulldir2")
mkdirp(t, "/_test/fulldir2/dir")
touch(t, "/_test/fulldir2/1")
touch(t, "/_test/fulldir2/2")
touch(t, "/_test/fulldir2/3")
res, err := client.ReadDir("/_test/fulldir2/")
require.NoError(t, err)
require.Equal(t, len(res), 4)
assert.EqualValues(t, "1", res[0].Name())
assert.False(t, res[0].IsDir())
assert.EqualValues(t, "2", res[1].Name())
assert.False(t, res[1].IsDir())
assert.EqualValues(t, "3", res[2].Name())
assert.False(t, res[2].IsDir())
assert.EqualValues(t, "dir", res[3].Name())
assert.True(t, res[3].IsDir())
}
func TestReadEmptyDir(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/emptydir")
mkdirp(t, "/_test/emptydir")
res, err := client.ReadDir("/_test/emptydir")
assert.NoError(t, err)
assert.EqualValues(t, 0, len(res))
}
func TestReadDirNonexistent(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/nonexistent")
res, err := client.ReadDir("/_test/nonexistent")
assertPathError(t, err, "open", "/_test/nonexistent", os.ErrNotExist)
assert.Nil(t, res)
}
func TestReadDirWithoutPermission(t *testing.T) {
mkdirpMask(t, "/_test/accessdenied", 0700)
touchMask(t, "/_test/accessdenied/foo", 0600)
client := getClientForUser(t, "gohdfs2")
res, err := client.ReadDir("/_test/accessdenied")
assertPathError(t, err, "readdir", "/_test/accessdenied", os.ErrPermission)
assert.Nil(t, res)
}