本文整理汇总了Golang中github.com/djbarber/ipfs-hack/Godeps/_workspace/src/bazil/org/fuse/fs/fstestutil.MountedT函数的典型用法代码示例。如果您正苦于以下问题:Golang MountedT函数的具体用法?Golang MountedT怎么用?Golang MountedT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MountedT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMountOptionSubtype
func TestMountOptionSubtype(t *testing.T) {
if runtime.GOOS == "darwin" {
t.Skip("OS X does not support Subtype")
}
if runtime.GOOS == "freebsd" {
t.Skip("FreeBSD does not support Subtype")
}
t.Parallel()
const name = "FuseTestMarker"
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.Dir{}},
fuse.Subtype(name),
)
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
info, err := fstestutil.GetMountInfo(mnt.Dir)
if err != nil {
t.Fatal(err)
}
if g, e := info.Type, "fuse."+name; g != e {
t.Errorf("wrong Subtype: %q != %q", g, e)
}
}
示例2: TestMountOptionReadOnly
func TestMountOptionReadOnly(t *testing.T) {
t.Parallel()
mnt, err := fstestutil.MountedT(t,
fstestutil.SimpleFS{createrDir{}},
fuse.ReadOnly(),
)
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
// This will be prevented by kernel-level access checking when
// ReadOnly is used.
f, err := os.Create(mnt.Dir + "/child")
if err == nil {
f.Close()
t.Fatal("expected an error")
}
perr, ok := err.(*os.PathError)
if !ok {
t.Fatalf("expected PathError, got %T: %v", err, err)
}
if perr.Err != syscall.EROFS {
t.Fatalf("expected EROFS, got %T: %v", err, err)
}
}
示例3: 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)
}
}
示例4: TestMmap
func TestMmap(t *testing.T) {
w := &mmap{}
w.data = make([]byte, mmapSize)
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.ChildMap{"child": w}})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
// Run the mmap-using parts of the test in a subprocess, to avoid
// an intentional page fault hanging the whole process (because it
// would need to be served by the same process, and there might
// not be a thread free to do that). Merely bumping GOMAXPROCS is
// not enough to prevent the hangs reliably.
child, err := childCmd("mmap")
if err != nil {
t.Fatal(err)
}
child.Dir = mnt.Dir
if err := child.Run(); err != nil {
t.Fatal(err)
}
got := w.bytes()
if g, e := len(got), mmapSize; g != e {
t.Fatalf("bad write length: %d != %d", g, e)
}
for i, g := range got {
// default '\x00' for writes[i] is good here
if e := mmapWrites[i]; g != e {
t.Errorf("wrong byte at offset %d: %q != %q", i, g, e)
}
}
}
示例5: TestMountOptionDefaultPermissions
func TestMountOptionDefaultPermissions(t *testing.T) {
if runtime.GOOS == "freebsd" {
t.Skip("FreeBSD does not support DefaultPermissions")
}
t.Parallel()
mnt, err := fstestutil.MountedT(t,
fstestutil.SimpleFS{
fstestutil.ChildMap{"child": unwritableFile{}},
},
fuse.DefaultPermissions(),
)
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
// This will be prevented by kernel-level access checking when
// DefaultPermissions is used.
f, err := os.OpenFile(mnt.Dir+"/child", os.O_WRONLY, 0000)
if err == nil {
f.Close()
t.Fatal("expected an error")
}
if !os.IsPermission(err) {
t.Fatalf("expected a permission error, got %T: %v", err, err)
}
}
示例6: testFtruncate
func testFtruncate(t *testing.T, toSize int64) {
t.Parallel()
f := &ftruncate{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.ChildMap{"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)
}
示例7: 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)
}
}
}
示例8: TestListxattr
func TestListxattr(t *testing.T) {
t.Parallel()
f := &listxattr{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.ChildMap{"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)
}
}
示例9: 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")
}
}
示例10: 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()
}
示例11: TestDirectWrite
func TestDirectWrite(t *testing.T) {
t.Parallel()
w := &directWrite{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.ChildMap{"child": w}})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
f, err := os.OpenFile(mnt.Dir+"/child", os.O_RDWR, 0666)
if err != nil {
t.Fatalf("Create: %v", err)
}
defer f.Close()
n, err := f.Write([]byte(hi))
if err != nil {
t.Fatalf("Write: %v", err)
}
if n != len(hi) {
t.Fatalf("short write; n=%d; hi=%d", n, len(hi))
}
err = f.Close()
if err != nil {
t.Fatalf("Close: %v", err)
}
if got := string(w.RecordedWriteData()); got != hi {
t.Errorf("write = %q, want %q", got, hi)
}
}
示例12: TestReadDirAll
func TestReadDirAll(t *testing.T) {
t.Parallel()
f := &readDirAll{}
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
}
}
示例13: TestTruncateWithOpen
func TestTruncateWithOpen(t *testing.T) {
t.Parallel()
f := &truncateWithOpen{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.ChildMap{"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)
}
示例14: 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)
}
}
示例15: TestAttrBad
func TestAttrBad(t *testing.T) {
t.Parallel()
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{fstestutil.ChildMap{"child": attrBad{}}})
_, err = os.Stat(mnt.Dir + "/child")
if nerr, ok := err.(*os.PathError); !ok || nerr.Err != syscall.ENAMETOOLONG {
t.Fatalf("wrong error: %v", err)
}
}