Commit 4db81d44 authored by Aaron Jacobs's avatar Aaron Jacobs

Pasted MknodTest from googlecloudplatform/gcsfuse@ff8a3f0.

parent 1dcc6791
......@@ -21,6 +21,7 @@ import (
"os"
"os/user"
"path"
"runtime"
"strconv"
"syscall"
"testing"
......@@ -87,21 +88,25 @@ func applyUmask(m os.FileMode) os.FileMode {
// Boilerplate
////////////////////////////////////////////////////////////////////////
type MemFSTest struct {
type memFSTest struct {
samples.SampleTest
}
func init() { RegisterTestSuite(&MemFSTest{}) }
func (t *MemFSTest) SetUp(ti *TestInfo) {
func (t *memFSTest) SetUp(ti *TestInfo) {
t.Server = memfs.NewMemFS(currentUid(), currentGid())
t.SampleTest.SetUp(ti)
}
////////////////////////////////////////////////////////////////////////
// Test functions
// Basics
////////////////////////////////////////////////////////////////////////
type MemFSTest struct {
memFSTest
}
func init() { RegisterTestSuite(&MemFSTest{}) }
func (t *MemFSTest) ContentsOfEmptyFileSystem() {
entries, err := fusetesting.ReadDirPicky(t.Dir)
......@@ -1614,3 +1619,91 @@ func (t *MemFSTest) RenameNonExistentFile() {
err = os.Rename(path.Join(t.Dir, "foo"), path.Join(t.Dir, "bar"))
ExpectThat(err, Error(HasSubstr("no such file")))
}
////////////////////////////////////////////////////////////////////////
// Mknod
////////////////////////////////////////////////////////////////////////
type MknodTest struct {
memFSTest
}
func init() { RegisterTestSuite(&MknodTest{}) }
func (t *MknodTest) File() {
// mknod(2) only works for root on OS X.
if runtime.GOOS == "darwin" {
return
}
var err error
p := path.Join(t.mfs.Dir(), "foo")
// Create
err = syscall.Mknod(p, syscall.S_IFREG|0600, 0)
AssertEq(nil, err)
// Stat
fi, err := os.Stat(p)
AssertEq(nil, err)
ExpectEq(path.Base(p), fi.Name())
ExpectEq(0, fi.Size())
ExpectEq(filePerms, fi.Mode())
// Read
contents, err := ioutil.ReadFile(p)
AssertEq(nil, err)
ExpectEq("", string(contents))
}
func (t *MknodTest) Directory() {
// mknod(2) only works for root on OS X.
if runtime.GOOS == "darwin" {
return
}
var err error
p := path.Join(t.mfs.Dir(), "foo")
// Quoth `man 2 mknod`: "Under Linux, this call cannot be used to create
// directories."
err = syscall.Mknod(p, syscall.S_IFDIR|0700, 0)
ExpectEq(syscall.EPERM, err)
}
func (t *MknodTest) AlreadyExists() {
// mknod(2) only works for root on OS X.
if runtime.GOOS == "darwin" {
return
}
var err error
p := path.Join(t.mfs.Dir(), "foo")
// Create (first)
err = ioutil.WriteFile(p, []byte("taco"), 0600)
AssertEq(nil, err)
// Create (second)
err = syscall.Mknod(p, syscall.S_IFREG|0600, 0)
ExpectEq(syscall.EEXIST, err)
// Read
contents, err := ioutil.ReadFile(p)
AssertEq(nil, err)
ExpectEq("taco", string(contents))
}
func (t *MknodTest) NonExistentParent() {
// mknod(2) only works for root on OS X.
if runtime.GOOS == "darwin" {
return
}
var err error
p := path.Join(t.mfs.Dir(), "foo/bar")
err = syscall.Mknod(p, syscall.S_IFREG|0600, 0)
ExpectEq(syscall.ENOENT, err)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment