Commit 31e0f8e4 authored by Aaron Jacobs's avatar Aaron Jacobs

Added integration tests for googlecloudplatform/gcsfuse#137.

parents 1dcc6791 6afe951e
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"os" "os"
"os/user" "os/user"
"path" "path"
"runtime"
"strconv" "strconv"
"syscall" "syscall"
"testing" "testing"
...@@ -87,21 +88,25 @@ func applyUmask(m os.FileMode) os.FileMode { ...@@ -87,21 +88,25 @@ func applyUmask(m os.FileMode) os.FileMode {
// Boilerplate // Boilerplate
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
type MemFSTest struct { type memFSTest struct {
samples.SampleTest 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.Server = memfs.NewMemFS(currentUid(), currentGid())
t.SampleTest.SetUp(ti) t.SampleTest.SetUp(ti)
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Test functions // Basics
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
type MemFSTest struct {
memFSTest
}
func init() { RegisterTestSuite(&MemFSTest{}) }
func (t *MemFSTest) ContentsOfEmptyFileSystem() { func (t *MemFSTest) ContentsOfEmptyFileSystem() {
entries, err := fusetesting.ReadDirPicky(t.Dir) entries, err := fusetesting.ReadDirPicky(t.Dir)
...@@ -1614,3 +1619,91 @@ func (t *MemFSTest) RenameNonExistentFile() { ...@@ -1614,3 +1619,91 @@ func (t *MemFSTest) RenameNonExistentFile() {
err = os.Rename(path.Join(t.Dir, "foo"), path.Join(t.Dir, "bar")) err = os.Rename(path.Join(t.Dir, "foo"), path.Join(t.Dir, "bar"))
ExpectThat(err, Error(HasSubstr("no such file"))) 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.Dir, "foo")
// Create
err = syscall.Mknod(p, syscall.S_IFREG|0642, 0)
AssertEq(nil, err)
// Stat
fi, err := os.Stat(p)
AssertEq(nil, err)
ExpectEq(path.Base(p), fi.Name())
ExpectEq(0, fi.Size())
ExpectEq(os.FileMode(0642), 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.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.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.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