Esempio n. 1
0
func testPathDoesNotExist(t *testing.T, label string, fs rwvfs.FileSystem, path string) {
	fi, err := fs.Stat(path)
	if err != nil && !os.IsNotExist(err) {
		t.Errorf("%s: Stat(%q): want os.IsNotExist-satisfying error, got %q", label, path, err)
	} else if err == nil {
		t.Errorf("%s: Stat(%q): want file to not exist, got existing file with FileInfo %+v", label, path, fi)
	}
}
Esempio n. 2
0
func testIsFile(t *testing.T, label string, fs rwvfs.FileSystem, path string) {
	fi, err := fs.Stat(path)
	if err != nil {
		t.Fatalf("%s: Stat(%q): %s", label, path, err)
	}

	if !fi.Mode().IsRegular() {
		t.Errorf("%s: got fs.Stat(%q) Mode().IsRegular() == false, want true", label, path)
	}
}
Esempio n. 3
0
func testIsDir(t *testing.T, label string, fs rwvfs.FileSystem, path string) {
	fi, err := fs.Stat(path)
	if err != nil {
		t.Fatalf("%s: Stat(%q): %s", label, path, err)
	}

	if fi == nil {
		t.Fatalf("%s: FileInfo (%q) == nil", label, path)
	}

	if !fi.IsDir() {
		t.Errorf("%s: got fs.Stat(%q) IsDir() == false, want true", label, path)
	}
}
Esempio n. 4
0
func testMkdir(t *testing.T, fs rwvfs.FileSystem) {
	label := fmt.Sprintf("%T", fs)

	if strings.Contains(label, "subFS") {
		if err := fs.Mkdir("/"); err != nil && !os.IsExist(err) {
			t.Fatalf("%s: subFS Mkdir(/): %s", label, err)
		}
	}
	if strings.Contains(label, "mapFS") {
		if err := fs.Mkdir("/"); err != nil && !os.IsExist(err) {
			t.Fatalf("%s: mapFS Mkdir(/): %s", label, err)
		}
	}

	fi, err := fs.Stat(".")
	if err != nil {
		t.Fatalf("%s: Stat(.): %s", label, err)
	}
	if !fi.Mode().IsDir() {
		t.Fatalf("%s: got Stat(.) FileMode %o, want IsDir", label, fi.Mode())
	}

	fi, err = fs.Stat("/")
	if err != nil {
		t.Fatalf("%s: Stat(/): %s", label, err)
	}
	if !fi.Mode().IsDir() {
		t.Fatalf("%s: got Stat(/) FileMode %o, want IsDir", label, fi.Mode())
	}

	if _, err := fs.ReadDir("."); err != nil {
		t.Fatalf("%s: ReadDir(.): %s", label, err)
	}
	if _, err := fs.ReadDir("/"); err != nil {
		t.Fatalf("%s: ReadDir(/): %s", label, err)
	}

	fis, err := fs.ReadDir("/")
	if err != nil {
		t.Fatalf("%s: ReadDir(/): %s", label, err)
	}
	if len(fis) != 0 {
		t.Fatalf("%s: ReadDir(/): got %d file infos (%v), want none (is it including .?)", label, len(fis), fis)
	}

	err = fs.Mkdir("dir0")
	if err != nil {
		t.Fatalf("%s: Mkdir(dir0): %s", label, err)
	}
	testIsDir(t, label, fs, "dir0")
	testIsDir(t, label, fs, "/dir0")

	err = fs.Mkdir("/dir1")
	if err != nil {
		t.Fatalf("%s: Mkdir(/dir1): %s", label, err)
	}
	testIsDir(t, label, fs, "dir1")
	testIsDir(t, label, fs, "/dir1")

	err = fs.Mkdir("/dir1")
	if !os.IsExist(err) {
		t.Errorf("%s: Mkdir(/dir1) again: got err %v, want os.IsExist-satisfying error", label, err)
	}

	err = fs.Mkdir("/parent-doesnt-exist/dir2")
	if !os.IsNotExist(err) {
		t.Errorf("%s: Mkdir(/parent-doesnt-exist/dir2): got error %v, want os.IsNotExist-satisfying error", label, err)
	}

	err = fs.Remove("/dir1")
	if err != nil {
		t.Errorf("%s: Remove(/dir1): %s", label, err)
	}
	testPathDoesNotExist(t, label, fs, "/dir1")
}
Esempio n. 5
0
// statIndex calls fs.Stat on the index's backing file or dir.
func statIndex(fs rwvfs.FileSystem, name string) (os.FileInfo, error) {
	return fs.Stat(fmt.Sprintf(indexFilename, name))
}