本文整理汇总了Golang中github.com/jacobsa/fuse/fusetesting.ReadDirPicky函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadDirPicky函数的具体用法?Golang ReadDirPicky怎么用?Golang ReadDirPicky使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadDirPicky函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Rmdir_Empty
func (t *ImplicitDirsTest) Rmdir_Empty() {
var err error
var entries []os.FileInfo
// Create two levels of directories. We can't make an empty implicit dir, so
// there must be a backing object for each.
AssertEq(
nil,
t.createObjects(
map[string]string{
"foo/": "",
"foo/bar/": "",
}))
// Remove the leaf.
err = os.Remove(path.Join(t.Dir, "foo/bar"))
AssertEq(nil, err)
// There should be nothing left in the parent.
entries, err = fusetesting.ReadDirPicky(path.Join(t.Dir, "foo"))
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
// Remove the parent.
err = os.Remove(path.Join(t.Dir, "foo"))
AssertEq(nil, err)
// Now the root directory should be empty, too.
entries, err = fusetesting.ReadDirPicky(t.Dir)
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
}
示例2: ReadDir_EmptySubDirectory
func (t *ForeignModsTest) ReadDir_EmptySubDirectory() {
// Set up an empty directory placeholder called 'bar'.
AssertEq(nil, t.createEmptyObjects([]string{"bar/"}))
// ReadDir
entries, err := fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
AssertEq(1, len(entries))
entries, err = fusetesting.ReadDirPicky(path.Join(t.mfs.Dir(), "bar"))
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
}
示例3: ReadDir_EmptyRoot
func (t *ForeignModsTest) ReadDir_EmptyRoot() {
// ReadDir
entries, err := fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
}
示例4: EmptyBucket
func (t *CachingTest) EmptyBucket() {
// ReadDir
entries, err := fusetesting.ReadDirPicky(t.Dir)
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
}
示例5: Inodes
func (t *ForeignModsTest) Inodes() {
// Set up two files and a directory placeholder.
AssertEq(
nil,
t.createEmptyObjects([]string{
"foo",
"bar/",
"baz",
}))
// List.
entries, err := fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
AssertEq(3, len(entries), "Names: %v", getFileNames(entries))
// Confirm all of the inodes are distinct.
inodesSeen := make(map[uint64]struct{})
for _, fileInfo := range entries {
stat := fileInfo.Sys().(*syscall.Stat_t)
_, ok := inodesSeen[stat.Ino]
AssertFalse(
ok,
"Duplicate inode (%v). File info: %v",
stat.Ino,
fileInfo)
inodesSeen[stat.Ino] = struct{}{}
}
}
示例6: OnlyDir_WithImplicitDir
func (t *GcsfuseTest) OnlyDir_WithImplicitDir() {
var err error
var fi os.FileInfo
// Mount only a single implicit directory from the bucket.
args := []string{
"--only-dir",
path.Dir(canned.ImplicitDirFile),
canned.FakeBucketName,
t.dir,
}
err = t.runGcsfuse(args)
AssertEq(nil, err)
defer unmount(t.dir)
// It should be as if t.dir points into the implicit directory
entries, err := fusetesting.ReadDirPicky(t.dir)
AssertEq(nil, err)
AssertEq(1, len(entries))
fi = entries[0]
ExpectEq(path.Base(canned.ImplicitDirFile), fi.Name())
ExpectEq(len(canned.ImplicitDirFile_Contents), fi.Size())
}
示例7: ReadBeyondEndOfFile
func (t *ForeignModsTest) ReadBeyondEndOfFile() {
const contents = "tacoburritoenchilada"
const contentLen = len(contents)
// Create an object.
AssertEq(nil, t.createWithContents("foo", contents))
// Wait for it to show up in the file system.
_, err := fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
// Attempt to open it.
f, err := os.Open(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)
defer func() { AssertEq(nil, f.Close()) }()
// Attempt to read beyond the end of the file.
_, err = f.Seek(int64(contentLen-1), 0)
AssertEq(nil, err)
buf := make([]byte, 2)
n, err := f.Read(buf)
AssertEq(1, n, "err: %v", err)
AssertEq(contents[contentLen-1], buf[0])
if err == nil {
n, err = f.Read(buf)
AssertEq(0, n)
}
}
示例8: OnlyDir_TrailingSlash
func (t *GcsfuseTest) OnlyDir_TrailingSlash() {
var err error
var fi os.FileInfo
// Mount only a single directory from the bucket, including a trailing slash.
args := []string{
"--only-dir",
path.Dir(canned.ExplicitDirFile) + "/",
canned.FakeBucketName,
t.dir,
}
err = t.runGcsfuse(args)
AssertEq(nil, err)
defer unmount(t.dir)
// It should be as if t.dir points into the bucket's first-level directory.
entries, err := fusetesting.ReadDirPicky(t.dir)
AssertEq(nil, err)
AssertEq(1, len(entries))
fi = entries[0]
ExpectEq(path.Base(canned.ExplicitDirFile), fi.Name())
ExpectEq(len(canned.ExplicitDirFile_Contents), fi.Size())
}
示例9: DirectoryObjectPresent
func (t *ImplicitDirsTest) DirectoryObjectPresent() {
var fi os.FileInfo
var entries []os.FileInfo
var err error
// Set up contents.
AssertEq(
nil,
t.createObjects(
map[string]string{
// Directory
"foo/": "",
}))
// Statting the name should return an entry for the directory.
fi, err = os.Stat(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)
ExpectEq("foo", fi.Name())
ExpectTrue(fi.IsDir())
// ReadDir should show the directory.
entries, err = fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
AssertEq(1, len(entries))
fi = entries[0]
ExpectEq("foo", fi.Name())
ExpectTrue(fi.IsDir())
}
示例10: NothingPresent
func (t *ImplicitDirsTest) NothingPresent() {
// ReadDir
entries, err := fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
}
示例11: ReadDir_ContentsInRoot
func (t *ForeignModsTest) ReadDir_ContentsInRoot() {
// Set up contents.
createTime := t.mtimeClock.Now()
AssertEq(
nil,
t.createObjects(
map[string]string{
// File
"foo": "taco",
// Directory
"bar/": "",
// File
"baz": "burrito",
}))
/////////////////////////
// ReadDir
/////////////////////////
entries, err := fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
AssertEq(3, len(entries), "Names: %v", getFileNames(entries))
var e os.FileInfo
// bar
e = entries[0]
ExpectEq("bar", e.Name())
ExpectEq(0, e.Size())
ExpectEq(dirPerms|os.ModeDir, e.Mode())
ExpectTrue(e.IsDir())
ExpectEq(1, e.Sys().(*syscall.Stat_t).Nlink)
ExpectEq(currentUid(), e.Sys().(*syscall.Stat_t).Uid)
ExpectEq(currentGid(), e.Sys().(*syscall.Stat_t).Gid)
// baz
e = entries[1]
ExpectEq("baz", e.Name())
ExpectEq(len("burrito"), e.Size())
ExpectEq(filePerms, e.Mode())
ExpectThat(e, fusetesting.MtimeIsWithin(createTime, timeSlop))
ExpectFalse(e.IsDir())
ExpectEq(1, e.Sys().(*syscall.Stat_t).Nlink)
ExpectEq(currentUid(), e.Sys().(*syscall.Stat_t).Uid)
ExpectEq(currentGid(), e.Sys().(*syscall.Stat_t).Gid)
// foo
e = entries[2]
ExpectEq("foo", e.Name())
ExpectEq(len("taco"), e.Size())
ExpectEq(filePerms, e.Mode())
ExpectThat(e, fusetesting.MtimeIsWithin(createTime, timeSlop))
ExpectFalse(e.IsDir())
ExpectEq(1, e.Sys().(*syscall.Stat_t).Nlink)
ExpectEq(currentUid(), e.Sys().(*syscall.Stat_t).Uid)
ExpectEq(currentGid(), e.Sys().(*syscall.Stat_t).Gid)
}
示例12: ConflictingNames_OneIsSymlink
func (t *ImplicitDirsTest) ConflictingNames_OneIsSymlink() {
var fi os.FileInfo
var entries []os.FileInfo
var err error
// Set up contents.
AssertEq(
nil,
t.createObjects(
map[string]string{
// Symlink
"foo": "",
// Directory
"foo/": "",
}))
// Cause "foo" to look like a symlink.
err = setSymlinkTarget(t.ctx, t.bucket, "foo", "")
AssertEq(nil, err)
// A listing of the parent should contain a directory named "foo" and a
// symlink named "foo\n".
entries, err = fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
AssertEq(2, len(entries))
fi = entries[0]
ExpectEq("foo", fi.Name())
ExpectEq(0, fi.Size())
ExpectEq(dirPerms|os.ModeDir, fi.Mode())
ExpectTrue(fi.IsDir())
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
fi = entries[1]
ExpectEq("foo\n", fi.Name())
ExpectEq(0, fi.Size())
ExpectEq(filePerms|os.ModeSymlink, fi.Mode())
ExpectFalse(fi.IsDir())
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
// Statting "foo" should yield the directory.
fi, err = os.Lstat(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)
ExpectEq("foo", fi.Name())
ExpectTrue(fi.IsDir())
// Statting "foo\n" should yield the symlink.
fi, err = os.Lstat(path.Join(t.mfs.Dir(), "foo\n"))
AssertEq(nil, err)
ExpectEq("foo\n", fi.Name())
ExpectEq(filePerms|os.ModeSymlink, fi.Mode())
}
示例13: ConflictingNames_PlaceholderNotPresent
func (t *ImplicitDirsTest) ConflictingNames_PlaceholderNotPresent() {
var fi os.FileInfo
var entries []os.FileInfo
var err error
// Set up contents.
AssertEq(
nil,
t.createObjects(
map[string]string{
// File
"foo": "taco",
// Implicit directory
"foo/bar": "",
}))
// A listing of the parent should contain a directory named "foo" and a
// file named "foo\n".
entries, err = fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
AssertEq(2, len(entries))
fi = entries[0]
ExpectEq("foo", fi.Name())
ExpectEq(0, fi.Size())
ExpectEq(dirPerms|os.ModeDir, fi.Mode())
ExpectTrue(fi.IsDir())
fi = entries[1]
ExpectEq("foo\n", fi.Name())
ExpectEq(len("taco"), fi.Size())
ExpectEq(len("taco"), fi.Size())
ExpectEq(filePerms, fi.Mode())
ExpectFalse(fi.IsDir())
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
// Statting "foo" should yield the directory.
fi, err = os.Stat(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)
ExpectEq("foo", fi.Name())
ExpectTrue(fi.IsDir())
// Statting "foo\n" should yield the file.
fi, err = os.Stat(path.Join(t.mfs.Dir(), "foo\n"))
AssertEq(nil, err)
ExpectEq("foo\n", fi.Name())
ExpectEq(len("taco"), fi.Size())
ExpectFalse(fi.IsDir())
}
示例14: ReadDir_Dir
func (t *HelloFSTest) ReadDir_Dir() {
entries, err := fusetesting.ReadDirPicky(path.Join(t.Dir, "dir"))
AssertEq(nil, err)
AssertEq(1, len(entries))
var fi os.FileInfo
// world
fi = entries[0]
ExpectEq("world", fi.Name())
ExpectEq(len("Hello, world!"), fi.Size())
ExpectEq(0444, fi.Mode())
ExpectEq(0, t.Clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
ExpectFalse(fi.IsDir())
}
示例15: ReadFromFile_Large
func (t *ForeignModsTest) ReadFromFile_Large() {
const contentLen = 1 << 20
contents := randString(contentLen)
// Create an object.
AssertEq(nil, t.createWithContents("foo", contents))
// Wait for it to show up in the file system.
_, err := fusetesting.ReadDirPicky(t.mfs.Dir())
AssertEq(nil, err)
// Attempt to open it.
f, err := os.Open(path.Join(t.mfs.Dir(), "foo"))
AssertEq(nil, err)
defer func() { AssertEq(nil, f.Close()) }()
// Read its entire contents.
slice, err := ioutil.ReadAll(f)
AssertEq(nil, err)
if contents != string(slice) {
ExpectTrue(
false,
"Expected:\n%v\n\nActual:\n%v",
hex.Dump([]byte(contents)),
hex.Dump(slice))
}
// Read from parts of it.
referenceReader := strings.NewReader(contents)
for trial := 0; trial < 1000; trial++ {
offset := rand.Int63n(contentLen + 1)
size := rand.Intn(int(contentLen - offset))
expected, err := readRange(referenceReader, offset, size)
AssertEq(nil, err)
actual, err := readRange(f, offset, size)
AssertEq(nil, err)
if expected != actual {
AssertTrue(
expected == actual,
"Expected:\n%s\nActual:\n%s",
hex.Dump([]byte(expected)),
hex.Dump([]byte(actual)))
}
}
}