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
|
package hdfs
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestChmod(t *testing.T) {
client := getClient(t)
touch(t, "/_test/tochmod")
err := client.Chmod("/_test/tochmod", 0777)
require.NoError(t, err)
fi, err := client.Stat("/_test/tochmod")
assert.NoError(t, err)
assert.EqualValues(t, 0777, fi.Mode())
}
func TestChmodDir(t *testing.T) {
client := getClient(t)
mkdirp(t, "/_test/dirtochmod")
err := client.Chmod("/_test/dirtochmod", 0777)
require.NoError(t, err)
fi, err := client.Stat("/_test/dirtochmod")
assert.NoError(t, err)
assert.EqualValues(t, 0777|os.ModeDir, fi.Mode())
}
func TestChmodNonexistent(t *testing.T) {
client := getClient(t)
baleet(t, "/_test/nonexistent")
err := client.Chmod("/_test/nonexistent", 0777)
assertPathError(t, err, "chmod", "/_test/nonexistent", os.ErrNotExist)
}
func TestChmodWithoutPermission(t *testing.T) {
client2 := getClientForUser(t, "gohdfs2")
mkdirp(t, "/_test/accessdenied")
err := client2.Chmod("/_test/accessdenied", 0777)
assertPathError(t, err, "chmod", "/_test/accessdenied", os.ErrPermission)
}
func TestChown(t *testing.T) {
superClient := getClientForSuperUser(t)
touch(t, "/_test/tochown")
err := superClient.Chown("/_test/tochown", "foo", "bar")
require.NoError(t, err)
fi, err := superClient.Stat("/_test/tochown")
assert.NoError(t, err)
assert.EqualValues(t, fi.(*FileInfo).Owner(), "foo")
assert.EqualValues(t, fi.(*FileInfo).OwnerGroup(), "bar")
}
func TestChownDir(t *testing.T) {
superClient := getClientForSuperUser(t)
mkdirp(t, "/_test/tochowndir")
err := superClient.Chown("/_test/tochowndir", "foo", "bar")
require.NoError(t, err)
fi, err := superClient.Stat("/_test/tochowndir")
assert.NoError(t, err)
assert.EqualValues(t, fi.(*FileInfo).Owner(), "foo")
assert.EqualValues(t, fi.(*FileInfo).OwnerGroup(), "bar")
}
func TestChownNonexistent(t *testing.T) {
superClient := getClientForSuperUser(t)
baleet(t, "/_test/nonexistent")
err := superClient.Chown("/_test/nonexistent", "gohdfs2", "")
assertPathError(t, err, "chown", "/_test/nonexistent", os.ErrNotExist)
}
func TestChownWithoutPermission(t *testing.T) {
client2 := getClientForUser(t, "gohdfs2")
mkdirp(t, "/_test/accessdenied")
err := client2.Chown("/_test/accessdenied", "owner", "")
assertPathError(t, err, "chown", "/_test/accessdenied", os.ErrPermission)
}
func TestChtimes(t *testing.T) {
client := getClient(t)
touch(t, "/_test/tochtime")
birthday := time.Date(1990, 1, 22, 14, 33, 35, 0, time.UTC)
client.Chtimes("/_test/tochtime", birthday, birthday)
fi, err := client.Stat("/_test/tochtime")
assert.NoError(t, err)
assert.EqualValues(t, birthday, fi.ModTime().UTC(), birthday)
assert.EqualValues(t, birthday, fi.(*FileInfo).AccessTime().UTC(), birthday)
}
|