本文整理匯總了Golang中camlistore/org/third_party/bazil/org/fuse/fs/fstestutil.MountedT函數的典型用法代碼示例。如果您正苦於以下問題:Golang MountedT函數的具體用法?Golang MountedT怎麽用?Golang MountedT使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MountedT函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestStatRoot
func TestStatRoot(t *testing.T) {
t.Parallel()
mnt, err := fstestutil.MountedT(t, root{})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
fi, err := os.Stat(mnt.Dir)
if err != nil {
t.Fatalf("root getattr failed with %v", err)
}
mode := fi.Mode()
if (mode & os.ModeType) != os.ModeDir {
t.Errorf("root is not a directory: %#v", fi)
}
if mode.Perm() != 0555 {
t.Errorf("root has weird access mode: %v", mode.Perm())
}
switch stat := fi.Sys().(type) {
case *syscall.Stat_t:
if stat.Ino != 1 {
t.Errorf("root has wrong inode: %v", stat.Ino)
}
if stat.Nlink != 1 {
t.Errorf("root has wrong link count: %v", stat.Nlink)
}
if stat.Uid != 0 {
t.Errorf("root has wrong uid: %d", stat.Uid)
}
if stat.Gid != 0 {
t.Errorf("root has wrong gid: %d", stat.Gid)
}
}
}
示例2: TestListxattr
func TestListxattr(t *testing.T) {
t.Parallel()
f := &listxattr{}
mnt, err := fstestutil.MountedT(t, childMapFS{"child": f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
buf := make([]byte, 8192)
n, err := syscallx.Listxattr(mnt.Dir+"/child", buf)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
buf = buf[:n]
if g, e := string(buf), "one\x00two\x00"; g != e {
t.Errorf("wrong listxattr content: %#v != %#v", g, e)
}
want := fuse.ListxattrRequest{
Size: 8192,
}
if g, e := f.RecordedListxattr(), want; g != e {
t.Fatalf("listxattr saw %+v, want %+v", g, e)
}
}
示例3: TestCreate
func TestCreate(t *testing.T) {
t.Parallel()
f := &create1{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
// uniform umask needed to make os.Create's 0666 into something
// reproducible
defer syscall.Umask(syscall.Umask(0022))
ff, err := os.Create(mnt.Dir + "/foo")
if err != nil {
t.Fatalf("create1 WriteFile: %v", err)
}
defer ff.Close()
err = syscall.Fsync(int(ff.Fd()))
if err != nil {
t.Fatalf("Fsync = %v", err)
}
if f.f.RecordedFsync() == (fuse.FsyncRequest{}) {
t.Errorf("never received expected fsync call")
}
ff.Close()
}
示例4: TestCreateWriteRemove
func TestCreateWriteRemove(t *testing.T) {
t.Parallel()
f := &create3{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
err = ioutil.WriteFile(mnt.Dir+"/foo", []byte(hi), 0666)
if err != nil {
t.Fatalf("create3 WriteFile: %v", err)
}
if got := string(f.f.RecordedWriteData()); got != hi {
t.Fatalf("create3 write = %q, want %q", got, hi)
}
err = os.Remove(mnt.Dir + "/foo")
if err != nil {
t.Fatalf("Remove: %v", err)
}
err = os.Remove(mnt.Dir + "/foo")
if err == nil {
t.Fatalf("second Remove = nil; want some error")
}
}
示例5: TestReadDir
func TestReadDir(t *testing.T) {
t.Parallel()
f := &readdir{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
fil, err := os.Open(mnt.Dir)
if err != nil {
t.Error(err)
return
}
defer fil.Close()
// go Readdir is just Readdirnames + Lstat, there's no point in
// testing that here; we have no consumption API for the real
// dirent data
names, err := fil.Readdirnames(100)
if err != nil {
t.Error(err)
return
}
t.Logf("Got readdir: %q", names)
if len(names) != 3 ||
names[0] != "one" ||
names[1] != "three" ||
names[2] != "two" {
t.Errorf(`expected 3 entries of "one", "three", "two", got: %q`, names)
return
}
}
示例6: TestSymlink
func TestSymlink(t *testing.T) {
t.Parallel()
f := &symlink1{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
const target = "/some-target"
err = os.Symlink(target, mnt.Dir+"/symlink.file")
if err != nil {
t.Fatalf("os.Symlink: %v", err)
}
want := fuse.SymlinkRequest{NewName: "symlink.file", Target: target}
if g, e := f.RecordedSymlink(), want; g != e {
t.Errorf("symlink saw %+v, want %+v", g, e)
}
gotName, err := os.Readlink(mnt.Dir + "/symlink.file")
if err != nil {
t.Fatalf("os.Readlink: %v", err)
}
if gotName != target {
t.Errorf("os.Readlink = %q; want %q", gotName, target)
}
}
示例7: TestTruncateWithOpen
func TestTruncateWithOpen(t *testing.T) {
t.Parallel()
f := &truncateWithOpen{}
mnt, err := fstestutil.MountedT(t, childMapFS{"child": f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
fil, err := os.OpenFile(mnt.Dir+"/child", os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
t.Error(err)
return
}
fil.Close()
gotr := f.RecordedSetattr()
if gotr == (fuse.SetattrRequest{}) {
t.Fatalf("no recorded SetattrRequest")
}
if g, e := gotr.Size, uint64(0); g != e {
t.Errorf("got Size = %q; want %q", g, e)
}
// osxfuse sets SetattrHandle here, linux does not
if g, e := gotr.Valid&^(fuse.SetattrLockOwner|fuse.SetattrHandle), fuse.SetattrSize; g != e {
t.Errorf("got Valid = %q; want %q", g, e)
}
t.Logf("Got request: %#v", gotr)
}
示例8: TestMknod
func TestMknod(t *testing.T) {
t.Parallel()
if os.Getuid() != 0 {
t.Skip("skipping unless root")
}
f := &mknod1{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
defer syscall.Umask(syscall.Umask(0))
err = syscall.Mknod(mnt.Dir+"/node", syscall.S_IFIFO|0666, 123)
if err != nil {
t.Fatalf("Mknod: %v", err)
}
want := fuse.MknodRequest{
Name: "node",
Mode: os.FileMode(os.ModeNamedPipe | 0666),
Rdev: uint32(123),
}
if runtime.GOOS == "linux" {
// Linux fuse doesn't echo back the rdev if the node
// isn't a device (we're using a FIFO here, as that
// bit is portable.)
want.Rdev = 0
}
if g, e := f.RecordedMknod(), want; g != e {
t.Fatalf("mknod saw %+v, want %+v", g, e)
}
}
示例9: testFtruncate
func testFtruncate(t *testing.T, toSize int64) {
t.Parallel()
f := &ftruncate{}
mnt, err := fstestutil.MountedT(t, childMapFS{"child": f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
{
fil, err := os.OpenFile(mnt.Dir+"/child", os.O_WRONLY, 0666)
if err != nil {
t.Error(err)
return
}
defer fil.Close()
err = fil.Truncate(toSize)
if err != nil {
t.Fatalf("Ftruncate: %v", err)
}
}
gotr := f.RecordedSetattr()
if gotr == (fuse.SetattrRequest{}) {
t.Fatalf("no recorded SetattrRequest")
}
if g, e := gotr.Size, uint64(toSize); g != e {
t.Errorf("got Size = %q; want %q", g, e)
}
if g, e := gotr.Valid&^fuse.SetattrLockOwner, fuse.SetattrHandle|fuse.SetattrSize; g != e {
t.Errorf("got Valid = %q; want %q", g, e)
}
t.Logf("Got request: %#v", gotr)
}
示例10: TestInterrupt
func TestInterrupt(t *testing.T) {
t.Parallel()
f := &interrupt{}
f.hanging = make(chan struct{}, 1)
mnt, err := fstestutil.MountedT(t, childMapFS{"child": f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
// start a subprocess that can hang until signaled
cmd := exec.Command("cat", mnt.Dir+"/child")
err = cmd.Start()
if err != nil {
t.Errorf("interrupt: cannot start cat: %v", err)
return
}
// try to clean up if child is still alive when returning
defer cmd.Process.Kill()
// wait till we're sure it's hanging in read
<-f.hanging
err = cmd.Process.Signal(os.Interrupt)
if err != nil {
t.Errorf("interrupt: cannot interrupt cat: %v", err)
return
}
p, err := cmd.Process.Wait()
if err != nil {
t.Errorf("interrupt: cat bork: %v", err)
return
}
switch ws := p.Sys().(type) {
case syscall.WaitStatus:
if ws.CoreDump() {
t.Errorf("interrupt: didn't expect cat to dump core: %v", ws)
}
if ws.Exited() {
t.Errorf("interrupt: didn't expect cat to exit normally: %v", ws)
}
if !ws.Signaled() {
t.Errorf("interrupt: expected cat to get a signal: %v", ws)
} else {
if ws.Signal() != os.Interrupt {
t.Errorf("interrupt: cat got wrong signal: %v", ws)
}
}
default:
t.Logf("interrupt: this platform has no test coverage")
}
}
示例11: TestReadAllWithHandleRead
func TestReadAllWithHandleRead(t *testing.T) {
t.Parallel()
mnt, err := fstestutil.MountedT(t, childMapFS{"child": readWithHandleRead{}})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
testReadAll(t, mnt.Dir+"/child")
}
示例12: TestMountOptionAllowRootThenAllowOther
func TestMountOptionAllowRootThenAllowOther(t *testing.T) {
t.Parallel()
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.Dir{}},
fuse.AllowRoot(),
fuse.AllowOther(),
)
if err == nil {
mnt.Close()
}
if g, e := err, fuse.ErrCannotCombineAllowOtherAndAllowRoot; g != e {
t.Fatalf("wrong error: %v != %v", g, e)
}
}
示例13: TestOpen
func TestOpen(t *testing.T) {
t.Parallel()
f := &open{}
mnt, err := fstestutil.MountedT(t, childMapFS{"child": f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
// node: mode only matters with O_CREATE
fil, err := os.OpenFile(mnt.Dir+"/child", os.O_WRONLY|os.O_APPEND, 0)
if err == nil {
t.Error("Open err == nil, expected ENAMETOOLONG")
fil.Close()
return
}
switch err2 := err.(type) {
case *os.PathError:
if err2.Err == syscall.ENAMETOOLONG {
break
}
t.Errorf("unexpected inner error: %#v", err2)
default:
t.Errorf("unexpected error: %v", err)
}
want := fuse.OpenRequest{Dir: false, Flags: fuse.OpenWriteOnly | fuse.OpenAppend}
if runtime.GOOS == "darwin" {
// osxfuse does not let O_APPEND through at all
//
// https://code.google.com/p/macfuse/issues/detail?id=233
// https://code.google.com/p/macfuse/issues/detail?id=132
// https://code.google.com/p/macfuse/issues/detail?id=133
want.Flags &^= fuse.OpenAppend
}
got := f.RecordedOpen()
if runtime.GOOS == "linux" {
// Linux <3.7 accidentally leaks O_CLOEXEC through to FUSE;
// avoid spurious test failures
got.Flags &^= fuse.OpenFlags(syscall.O_CLOEXEC)
}
if g, e := got, want; g != e {
t.Errorf("open saw %v, want %v", g, e)
return
}
}
示例14: TestListxattrSize
func TestListxattrSize(t *testing.T) {
t.Parallel()
f := &listxattrSize{}
mnt, err := fstestutil.MountedT(t, childMapFS{"child": f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
n, err := syscallx.Listxattr(mnt.Dir+"/child", nil)
if err != nil {
t.Errorf("Listxattr unexpected error: %v", err)
return
}
if g, e := n, len("one\x00two\x00"); g != e {
t.Errorf("Getxattr incorrect size: %d != %d", g, e)
}
}
示例15: TestMountOptionCommaError
func TestMountOptionCommaError(t *testing.T) {
t.Parallel()
// this test is not tied to FSName, but needs just some option
// with string content
var name = "FuseTest,Marker"
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.Dir{}},
fuse.FSName(name),
)
switch {
case err == nil:
mnt.Close()
t.Fatal("expected an error about commas")
case err.Error() == `mount options cannot contain commas on OS X: "fsname"="FuseTest,Marker"`:
// all good
default:
t.Fatalf("expected an error about commas, got: %v", err)
}
}