Esempio n. 1
0
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)
	}
}
Esempio n. 2
0
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)
	}
}
Esempio n. 3
0
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)
	}
}
Esempio n. 4
0
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)
	}
}
Esempio n. 5
0
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)
	}
}
Esempio n. 6
0
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)
		}
	}
}
Esempio n. 7
0
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)
	}
}
Esempio n. 8
0
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)
	}
}
Esempio n. 9
0
func MyFS() *myFS {
	return &myFS{
		vfs.Dummy(errors.New("Not implemented yet!")),
	}
}