diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2017-12-05 08:10:13 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2017-12-05 08:10:13 -0500 |
| commit | 149f2b13d110f34f048e5942466faea4e1a4a870 (patch) | |
| tree | 41a259362fefcfc99f95b26fda532a26fd4ba4f0 /vendor/github.com/blang | |
| parent | f6e20ca5ecb47c067fccca8d61e937f35348e7a5 (diff) | |
Pruning dependencies with `dep prune`
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'vendor/github.com/blang')
| -rw-r--r-- | vendor/github.com/blang/vfs/mountfs/doc.go | 3 | ||||
| -rw-r--r-- | vendor/github.com/blang/vfs/mountfs/example_test.go | 23 | ||||
| -rw-r--r-- | vendor/github.com/blang/vfs/mountfs/mountfs.go | 179 | ||||
| -rw-r--r-- | vendor/github.com/blang/vfs/mountfs/mountfs_test.go | 390 | ||||
| -rw-r--r-- | vendor/github.com/blang/vfs/prefixfs/prefixfs.go | 63 | ||||
| -rw-r--r-- | vendor/github.com/blang/vfs/prefixfs/prefixfs_test.go | 229 |
6 files changed, 0 insertions, 887 deletions
diff --git a/vendor/github.com/blang/vfs/mountfs/doc.go b/vendor/github.com/blang/vfs/mountfs/doc.go deleted file mode 100644 index 64debd63..00000000 --- a/vendor/github.com/blang/vfs/mountfs/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package mountfs defines a filesystem supporting -// the composition of multiple filesystems by mountpoints. -package mountfs diff --git a/vendor/github.com/blang/vfs/mountfs/example_test.go b/vendor/github.com/blang/vfs/mountfs/example_test.go deleted file mode 100644 index b9ce7b46..00000000 --- a/vendor/github.com/blang/vfs/mountfs/example_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package mountfs_test - -import ( - "github.com/blang/vfs" - "github.com/blang/vfs/memfs" - "github.com/blang/vfs/mountfs" -) - -func ExampleMountFS() { - // Create a vfs supporting mounts - // The root fs is accessing the filesystem of the underlying OS - fs := mountfs.Create(vfs.OS()) - - // Mount a memfs inside /memfs - // /memfs may not exist - fs.Mount(memfs.Create(), "/memfs") - - // This will create /testdir inside the memfs - fs.Mkdir("/memfs/testdir", 0777) - - // This will create /tmp/testdir inside your OS fs - fs.Mkdir("/tmp/testdir", 0777) -} diff --git a/vendor/github.com/blang/vfs/mountfs/mountfs.go b/vendor/github.com/blang/vfs/mountfs/mountfs.go deleted file mode 100644 index aa0396c3..00000000 --- a/vendor/github.com/blang/vfs/mountfs/mountfs.go +++ /dev/null @@ -1,179 +0,0 @@ -package mountfs - -import ( - "errors" - "github.com/blang/vfs" - "os" - filepath "path" - "strings" -) - -// ErrBoundary is returned if an operation -// can not act across filesystem boundaries. -var ErrBoundary = errors.New("Crossing boundary") - -// Create a new MountFS based on a root filesystem. -func Create(rootFS vfs.Filesystem) *MountFS { - return &MountFS{ - rootFS: rootFS, - mounts: make(map[string]vfs.Filesystem), - parents: make(map[string][]string), - } -} - -// MountFS represents a filesystem build upon a root filesystem -// and multiple filesystems can be mounted inside it. -// In contrast to unix filesystems, the mount path may -// not be a directory or event exist. -// -// Only filesystems with the same path separator are compatible. -// It's not possible to mount a specific source directory, only the -// root of the filesystem can be mounted, use a chroot in this case. -// The resulting filesystem is case-sensitive. -type MountFS struct { - rootFS vfs.Filesystem - mounts map[string]vfs.Filesystem - parents map[string][]string -} - -// Mount mounts a filesystem on the given path. -// Mounts inside mounts are supported, the longest path match will be taken. -// Mount paths may be overwritten if set on the same path. -// Path `/` can be used to change rootfs. -// Only absolute paths are allowed. -func (fs *MountFS) Mount(mount vfs.Filesystem, path string) error { - pathSeparator := string(fs.rootFS.PathSeparator()) - - // Clean path and make absolute - path = filepath.Clean(path) - segm := vfs.SplitPath(path, pathSeparator) - segm[0] = "" // make absolute - path = strings.Join(segm, pathSeparator) - - // Change rootfs disabled - if path == "" { - fs.rootFS = mount - return nil - } - - parent := strings.Join(segm[0:len(segm)-1], pathSeparator) - if parent == "" { - parent = "/" - } - fs.parents[parent] = append(fs.parents[parent], path) - fs.mounts[path] = mount - return nil -} - -// PathSeparator returns the path separator -func (fs MountFS) PathSeparator() uint8 { - return fs.rootFS.PathSeparator() -} - -// findMount finds a valid mountpoint for the given path. -// It returns the corresponding filesystem and the path inside of this filesystem. -func findMount(path string, mounts map[string]vfs.Filesystem, fallback vfs.Filesystem, pathSeparator string) (vfs.Filesystem, string) { - path = filepath.Clean(path) - segs := vfs.SplitPath(path, pathSeparator) - l := len(segs) - for i := l; i > 0; i-- { - mountPath := strings.Join(segs[0:i], pathSeparator) - if fs, ok := mounts[mountPath]; ok { - return fs, "/" + strings.Join(segs[i:l], pathSeparator) - } - } - return fallback, path -} - -type innerFile struct { - vfs.File - name string -} - -// Name returns the full path inside mountfs -func (f innerFile) Name() string { - return f.name -} - -// OpenFile find the mount of the given path and executes OpenFile -// on the corresponding filesystem. -// It wraps the resulting file to return the path inside mountfs on Name() -func (fs MountFS) OpenFile(name string, flag int, perm os.FileMode) (vfs.File, error) { - mount, innerPath := findMount(name, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - file, err := mount.OpenFile(innerPath, flag, perm) - return innerFile{File: file, name: name}, err -} - -// Remove removes a file or directory -func (fs MountFS) Remove(name string) error { - mount, innerPath := findMount(name, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - return mount.Remove(innerPath) -} - -// Rename renames a file. -// Renames across filesystems are not allowed. -func (fs MountFS) Rename(oldpath, newpath string) error { - oldMount, oldInnerPath := findMount(oldpath, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - newMount, newInnerPath := findMount(newpath, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - if oldMount != newMount { - return ErrBoundary - } - return oldMount.Rename(oldInnerPath, newInnerPath) -} - -// Mkdir creates a directory -func (fs MountFS) Mkdir(name string, perm os.FileMode) error { - mount, innerPath := findMount(name, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - return mount.Mkdir(innerPath, perm) -} - -type innerFileInfo struct { - os.FileInfo - name string -} - -func (fi innerFileInfo) Name() string { - return fi.name -} - -// Stat returns the fileinfo of a file -func (fs MountFS) Stat(name string) (os.FileInfo, error) { - mount, innerPath := findMount(name, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - fi, err := mount.Stat(innerPath) - if innerPath == "/" { - return innerFileInfo{FileInfo: fi, name: filepath.Base(name)}, err - } - return fi, err -} - -// Lstat returns the fileinfo of a file or link. -func (fs MountFS) Lstat(name string) (os.FileInfo, error) { - mount, innerPath := findMount(name, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - fi, err := mount.Lstat(innerPath) - if innerPath == "/" { - return innerFileInfo{FileInfo: fi, name: filepath.Base(name)}, err - } - return fi, err -} - -// ReadDir reads the directory named by path and returns a list of sorted directory entries. -func (fs MountFS) ReadDir(path string) ([]os.FileInfo, error) { - path = filepath.Clean(path) - mount, innerPath := findMount(path, fs.mounts, fs.rootFS, string(fs.PathSeparator())) - - fis, err := mount.ReadDir(innerPath) - if err != nil { - return fis, err - } - - // Add mountpoints - if childs, ok := fs.parents[path]; ok { - for _, c := range childs { - mfi, err := fs.Stat(c) - if err == nil { - fis = append(fis, mfi) - } - } - } - return fis, err -} diff --git a/vendor/github.com/blang/vfs/mountfs/mountfs_test.go b/vendor/github.com/blang/vfs/mountfs/mountfs_test.go deleted file mode 100644 index 03ea839c..00000000 --- a/vendor/github.com/blang/vfs/mountfs/mountfs_test.go +++ /dev/null @@ -1,390 +0,0 @@ -package mountfs - -import ( - "errors" - "github.com/blang/vfs" - "os" - "testing" -) - -type mountTest struct { - mounts []string - results map[string]mtres -} - -type mtres struct { - mountPath string - innerPath string -} - -var mountTests = []mountTest{ - { - []string{ - "/tmp", - }, - map[string]mtres{ - "/": {"/", "/"}, - "/tmp": {"/tmp", "/"}, - "/tmp/test": {"/tmp", "/test"}, - }, - }, - - { - []string{ - "/home", - "/home/user1", - "/home/user2", - }, - map[string]mtres{ - "/": {"/", "/"}, - "/tmp": {"/", "/tmp"}, - "/tmp/test": {"/", "/tmp/test"}, - "/home": {"/home", "/"}, - "/home/user1": {"/home/user1", "/"}, - "/home/user2": {"/home/user2", "/"}, - "/home/user1/subdir": {"/home/user1", "/subdir"}, - "/home/user2/subdir/subsubdir": {"/home/user2", "/subdir/subsubdir"}, - }, - }, -} - -func TestInterface(t *testing.T) { - _ = vfs.Filesystem(Create(nil)) -} - -func TestFindMount(t *testing.T) { - for i, mtest := range mountTests { - mounts := make(map[string]vfs.Filesystem) - revmounts := make(map[vfs.Filesystem]string) - for _, mount := range mtest.mounts { - fs := vfs.Dummy(nil) - mounts[mount] = fs - revmounts[fs] = mount - } - fallback := vfs.Dummy(nil) - for path, expRes := range mtest.results { - expMountPath := expRes.mountPath - expInnerPath := expRes.innerPath - - res, resInnerPath := findMount(path, mounts, fallback, "/") - if res == nil { - t.Errorf("Got nil") - continue - } - if res == fallback { - if expMountPath != "/" { - t.Fatalf("Invalid mount result test case %d, mounts: %q, path: %q, expected: %q, got: %q", i, mtest.mounts, path, expMountPath, "/") - } - continue - } - - if resMountPath, ok := revmounts[res]; ok { - if resMountPath != expMountPath { - t.Fatalf("Invalid mount, test case %d, mounts: %q, path: %q, expected: %q, got: %q", i, mtest.mounts, path, expMountPath, resMountPath) - } - if resInnerPath != expInnerPath { - t.Fatalf("Invalid inner path, test case %d, mounts: %q, path: %q, expected: %q, got: %q", i, mtest.mounts, path, expInnerPath, resInnerPath) - } - continue - } - t.Fatalf("Invalid mount result test case %d, mounts: %q, path: %q, expected: %q, got invalid result", i, mtest.mounts, path, expMountPath) - } - } -} - -type testDummyFS struct { - vfs.Filesystem - lastPath string - lastPath2 string -} - -func (fs testDummyFS) OpenFile(name string, flag int, perm os.FileMode) (vfs.File, error) { - return vfs.DummyFile(errors.New("Mount")), nil -} - -func TestCreate(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := vfs.Dummy(errMount) - fs := Create(rootFS) - if err := fs.Mkdir("/dir", 0); err != errRoot { - t.Errorf("Expected error from rootFS: %s", err) - } - - fs.Mount(mountFS, "/tmp") - if err := fs.Mkdir("/tmp/dir", 0); err != errMount { - t.Errorf("Expected error from mountFS: %s", err) - } - - // Change rootfs - fs.Mount(mountFS, "/") - if err := fs.Mkdir("/dir2", 0); err != errMount { - t.Errorf("Expected error from mountFS: %s", err) - } -} - -func TestOpenFile(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - f, err := fs.OpenFile("/tmp/testfile", os.O_CREATE, 0) - if err != nil { - t.Errorf("Unexpected error: %s", err) - } - if n := f.Name(); n != "/tmp/testfile" { - t.Errorf("Unexpected filename: %s", n) - } -} - -func (fs *testDummyFS) Mkdir(name string, perm os.FileMode) error { - fs.lastPath = name - return fs.Filesystem.Mkdir(name, perm) -} - -func TestMkdir(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - err := fs.Mkdir("/tmp/testdir", 0) - if err != errMount { - t.Errorf("Wrong filesystem selected: %s", err) - } - if n := mountFS.lastPath; n != "/testdir" { - t.Errorf("Incorrect inner name: %s", n) - } -} - -func (fs *testDummyFS) Remove(name string) error { - fs.lastPath = name - return fs.Filesystem.Remove(name) -} - -func TestRemove(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - err := fs.Remove("/tmp/testdir") - if err != errMount { - t.Errorf("Wrong filesystem selected: %s", err) - } - if n := mountFS.lastPath; n != "/testdir" { - t.Errorf("Incorrect inner name: %s", n) - } -} - -func (fs *testDummyFS) Rename(oldpath, newpath string) error { - fs.lastPath = oldpath - fs.lastPath2 = newpath - return fs.Filesystem.Rename(oldpath, newpath) -} - -func TestRename(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - err := fs.Rename("/tmp/testfile1", "/tmp/testfile2") - if err != errMount { - t.Errorf("Wrong filesystem selected: %s", err) - } - if n := mountFS.lastPath; n != "/testfile1" { - t.Errorf("Incorrect inner name (oldpath): %s", n) - } - if n := mountFS.lastPath2; n != "/testfile2" { - t.Errorf("Incorrect inner name (newpath): %s", n) - } -} - -func TestRenameBoundaries(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := vfs.Dummy(errMount) - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - err := fs.Rename("/tmp/testfile1", "/testfile2") - if err != ErrBoundary { - t.Errorf("Invalid error, should return boundaries error: %s", err) - } -} - -func (fs *testDummyFS) Stat(name string) (os.FileInfo, error) { - fs.lastPath = name - return vfs.DumFileInfo{ - IName: name, - }, nil -} - -func TestStat(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - _, err := fs.Stat("/tmp/testfile1") - if err != nil { - t.Errorf("Wrong filesystem selected: %s", err) - } - - if n := mountFS.lastPath; n != "/testfile1" { - t.Errorf("Incorrect inner name: %s", n) - } -} - -func TestStatMountPoint(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - fi, err := fs.Stat("/tmp") - if err != nil { - t.Errorf("Wrong filesystem selected: %s", err) - } - - if n := mountFS.lastPath; n != "/" { - t.Errorf("Incorrect inner name: %s", n) - } - - if n := fi.Name(); n != "tmp" { - t.Errorf("Mountpoint should be return correct name, got instead: %s", n) - } -} - -func (fs *testDummyFS) Lstat(name string) (os.FileInfo, error) { - fs.lastPath = name - return vfs.DumFileInfo{ - IName: name, - }, nil -} - -func TestLstat(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - _, err := fs.Lstat("/tmp/testfile1") - if err != nil { - t.Errorf("Wrong filesystem selected: %s", err) - } - - if n := mountFS.lastPath; n != "/testfile1" { - t.Errorf("Incorrect inner name: %s", n) - } -} - -func TestLstatMountPoint(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - fi, err := fs.Lstat("/tmp") - if err != nil { - t.Errorf("Wrong filesystem selected: %s", err) - } - - if n := mountFS.lastPath; n != "/" { - t.Errorf("Incorrect inner name: %s", n) - } - - if n := fi.Name(); n != "tmp" { - t.Errorf("Mountpoint should be return correct name, got instead: %s", n) - } -} - -func (fs *testDummyFS) ReadDir(path string) ([]os.FileInfo, error) { - fs.lastPath = path - return []os.FileInfo{ - vfs.DumFileInfo{ - IName: "testcontent", - }, - }, nil -} - -func TestReadDir(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := vfs.Dummy(errRoot) - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - fis, err := fs.ReadDir("/tmp") - if err != nil { - t.Errorf("Wrong filesystem selected: %s", err) - } - - if n := mountFS.lastPath; n != "/" { - t.Errorf("Incorrect inner name: %s", n) - } - - if len(fis) != 1 || fis[0].Name() != "testcontent" { - t.Errorf("Expected fake file, but got: %s", fis) - } -} - -func TestReadDirMountPoints(t *testing.T) { - errRoot := errors.New("Rootfs") - errMount := errors.New("Mount") - rootFS := &testDummyFS{Filesystem: vfs.Dummy(errRoot)} - mountFS := &testDummyFS{Filesystem: vfs.Dummy(errMount)} - fs := Create(rootFS) - fs.Mount(mountFS, "/tmp") - - // Test selection of correct fs - fis, err := fs.ReadDir("/") - if err != nil { - t.Errorf("Wrong filesystem selected: %s", err) - } - - if n := rootFS.lastPath; n != "/" { - t.Errorf("Incorrect inner name: %s", n) - } - - if l := len(fis); l != 2 { - t.Fatalf("Expected 2 files, one fake, one mountpoint: %d, %s", l, fis) - } - if n := fis[0].Name(); n != "testcontent" { - t.Errorf("Expected fake file, but got: %s", fis) - } - if n := fis[1].Name(); n != "tmp" { - t.Errorf("Expected mountpoint, but got: %s", fis) - } -} diff --git a/vendor/github.com/blang/vfs/prefixfs/prefixfs.go b/vendor/github.com/blang/vfs/prefixfs/prefixfs.go deleted file mode 100644 index 6b84dfb9..00000000 --- a/vendor/github.com/blang/vfs/prefixfs/prefixfs.go +++ /dev/null @@ -1,63 +0,0 @@ -package prefixfs - -import ( - "os" - - "github.com/blang/vfs" -) - -// A FS that prefixes the path in each vfs.Filesystem operation. -type FS struct { - vfs.Filesystem - - // Prefix is used to prefix the path in each vfs.Filesystem operation. - Prefix string -} - -// Create returns a file system that prefixes all paths and forwards to root. -func Create(root vfs.Filesystem, prefix string) *FS { - return &FS{root, prefix} -} - -// PrefixPath returns path with the prefix prefixed. -func (fs *FS) PrefixPath(path string) string { - return fs.Prefix + string(fs.PathSeparator()) + path -} - -// PathSeparator implements vfs.Filesystem. -func (fs *FS) PathSeparator() uint8 { return fs.Filesystem.PathSeparator() } - -// OpenFile implements vfs.Filesystem. -func (fs *FS) OpenFile(name string, flag int, perm os.FileMode) (vfs.File, error) { - return fs.Filesystem.OpenFile(fs.PrefixPath(name), flag, perm) -} - -// Remove implements vfs.Filesystem. -func (fs *FS) Remove(name string) error { - return fs.Filesystem.Remove(fs.PrefixPath(name)) -} - -// Rename implements vfs.Filesystem. -func (fs *FS) Rename(oldpath, newpath string) error { - return fs.Filesystem.Rename(fs.PrefixPath(oldpath), fs.PrefixPath(newpath)) -} - -// Mkdir implements vfs.Filesystem. -func (fs *FS) Mkdir(name string, perm os.FileMode) error { - return fs.Filesystem.Mkdir(fs.PrefixPath(name), perm) -} - -// Stat implements vfs.Filesystem. -func (fs *FS) Stat(name string) (os.FileInfo, error) { - return fs.Filesystem.Stat(fs.PrefixPath(name)) -} - -// Lstat implements vfs.Filesystem. -func (fs *FS) Lstat(name string) (os.FileInfo, error) { - return fs.Filesystem.Lstat(fs.PrefixPath(name)) -} - -// ReadDir implements vfs.Filesystem. -func (fs *FS) ReadDir(path string) ([]os.FileInfo, error) { - return fs.Filesystem.ReadDir(fs.PrefixPath(path)) -} diff --git a/vendor/github.com/blang/vfs/prefixfs/prefixfs_test.go b/vendor/github.com/blang/vfs/prefixfs/prefixfs_test.go deleted file mode 100644 index c04e7464..00000000 --- a/vendor/github.com/blang/vfs/prefixfs/prefixfs_test.go +++ /dev/null @@ -1,229 +0,0 @@ -package prefixfs - -import ( - "os" - "reflect" - "testing" - - "github.com/blang/vfs" - "github.com/blang/vfs/memfs" -) - -const prefixPath = "/prefix" - -func prefix(path string) string { - return prefixPath + "/" + path -} - -func rootfs() vfs.Filesystem { - rfs := memfs.Create() - rfs.Mkdir(prefixPath, 0777) - return rfs -} - -func TestPathSeparator(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - if fs.PathSeparator() != rfs.PathSeparator() { - t.Errorf("fs.PathSeparator() != %v", rfs.PathSeparator()) - } -} - -func TestOpenFile(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - f, err := fs.OpenFile("file", os.O_CREATE, 0666) - defer f.Close() - if err != nil { - t.Errorf("OpenFile: %v", err) - } - - _, err = rfs.Stat(prefix("file")) - if os.IsNotExist(err) { - t.Errorf("root:%v not found (%v)", prefix("file"), err) - } -} - -func TestRemove(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - f, err := fs.OpenFile("file", os.O_CREATE, 0666) - defer f.Close() - if err != nil { - t.Errorf("OpenFile: %v", err) - } - - err = fs.Remove("file") - if err != nil { - t.Errorf("Remove: %v", err) - } - - _, err = rfs.Stat(prefix("file")) - if os.IsExist(err) { - t.Errorf("root:%v found (%v)", prefix("file"), err) - } -} - -func TestRename(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - f, err := fs.OpenFile("file", os.O_CREATE, 0666) - defer f.Close() - if err != nil { - t.Errorf("OpenFile: %v", err) - } - - err = fs.Rename("file", "file2") - if err != nil { - t.Errorf("Rename: %v", err) - } - - _, err = rfs.Stat(prefix("file2")) - if os.IsNotExist(err) { - t.Errorf("root:%v not found (%v)", prefix("file2"), err) - } -} - -func TestMkdir(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - err := fs.Mkdir("dir", 0777) - if err != nil { - t.Errorf("Mkdir: %v", err) - } - - _, err = rfs.Stat(prefix("dir")) - if os.IsNotExist(err) { - t.Errorf("root:%v not found (%v)", prefix("dir"), err) - } -} - -func TestStat(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - f, err := fs.OpenFile("file", os.O_CREATE, 0666) - defer f.Close() - if err != nil { - t.Errorf("OpenFile: %v", err) - } - - fi, err := fs.Stat("file") - if os.IsNotExist(err) { - t.Errorf("fs.Stat: %v", err) - } - - rfi, err := rfs.Stat(prefix("file")) - if os.IsNotExist(err) { - t.Errorf("rfs.Stat: %v", err) - } - - if fi.Name() != rfi.Name() { - t.Errorf("FileInfo: Name not equal (fs:%v != root:%v)", fi.Name(), rfi.Name()) - } - - if fi.Size() != rfi.Size() { - t.Errorf("FileInfo: Size not equal (fs:%v != root:%v)", fi.Size(), rfi.Size()) - } - - if fi.Mode() != rfi.Mode() { - t.Errorf("FileInfo: Mode not equal (fs:%v != root:%v)", fi.Mode(), rfi.Mode()) - } - - if fi.ModTime() != rfi.ModTime() { - t.Errorf("FileInfo: ModTime not equal (fs:%v != root:%v)", fi.ModTime(), rfi.ModTime()) - } - - if fi.IsDir() != rfi.IsDir() { - t.Errorf("FileInfo: Mode not equal (fs:%v != root:%v)", fi.IsDir(), rfi.IsDir()) - } - - if fi.Sys() != rfi.Sys() { - t.Errorf("FileInfo: Sys not equal (fs:%v != root:%v)", fi.Sys(), rfi.Sys()) - } -} - -func TestLstat(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - f, err := fs.OpenFile("file", os.O_CREATE, 0666) - defer f.Close() - if err != nil { - t.Errorf("OpenFile: %v", err) - } - - fi, err := fs.Lstat("file") - if os.IsNotExist(err) { - t.Errorf("fs.Lstat: %v", err) - } - - rfi, err := rfs.Lstat(prefix("file")) - if os.IsNotExist(err) { - t.Errorf("rfs.Lstat: %v", err) - } - - if fi.Name() != rfi.Name() { - t.Errorf("FileInfo: Name not equal (fs:%v != root:%v)", fi.Name(), rfi.Name()) - } - - if fi.Size() != rfi.Size() { - t.Errorf("FileInfo: Size not equal (fs:%v != root:%v)", fi.Size(), rfi.Size()) - } - - if fi.Mode() != rfi.Mode() { - t.Errorf("FileInfo: Mode not equal (fs:%v != root:%v)", fi.Mode(), rfi.Mode()) - } - - if fi.ModTime() != rfi.ModTime() { - t.Errorf("FileInfo: ModTime not equal (fs:%v != root:%v)", fi.ModTime(), rfi.ModTime()) - } - - if fi.IsDir() != rfi.IsDir() { - t.Errorf("FileInfo: Mode not equal (fs:%v != root:%v)", fi.IsDir(), rfi.IsDir()) - } - - if fi.Sys() != rfi.Sys() { - t.Errorf("FileInfo: Sys not equal (fs:%v != root:%v)", fi.Sys(), rfi.Sys()) - } -} - -func TestReadDir(t *testing.T) { - rfs := rootfs() - fs := Create(rfs, prefixPath) - - err := fs.Mkdir("dir", 0777) - if err != nil { - t.Errorf("Mkdir: %v", err) - } - - _, err = rfs.Stat(prefix("dir")) - if os.IsNotExist(err) { - t.Errorf("root:%v not found (%v)", prefix("dir"), err) - } - - f, err := fs.OpenFile("dir/file", os.O_CREATE, 0666) - defer f.Close() - if err != nil { - t.Errorf("OpenFile: %v", err) - } - - s, err := fs.ReadDir("dir") - if err != nil { - t.Errorf("fs.ReadDir: %v", err) - } - - rs, err := rfs.ReadDir(prefix("dir")) - if err != nil { - t.Errorf("rfs.ReadDir: %v", err) - } - - if !reflect.DeepEqual(s, rs) { - t.Error("ReadDir: slices not equal") - } -} |
