tests: don't call t.Fatal in checkExampleFS

Calling t.Fatal means that the parent test has no chance
to clean up.
This commit is contained in:
Jakob Unterwurzacher 2016-11-26 15:17:15 +01:00
parent a6006c0d2b
commit 3f5c48e058
2 changed files with 26 additions and 16 deletions

View File

@ -15,7 +15,8 @@ func checkExampleFS(t *testing.T, dir string, rw bool) {
statusFile := filepath.Join(dir, "status.txt")
contentBytes, err := ioutil.ReadFile(statusFile)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
content := string(contentBytes)
if content != statusTxtContent {
@ -25,7 +26,8 @@ func checkExampleFS(t *testing.T, dir string, rw bool) {
symlink := filepath.Join(dir, "rel")
target, err := os.Readlink(symlink)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
if target != "status.txt" {
t.Errorf("Unexpected link target: %s\n", target)
@ -34,12 +36,12 @@ func checkExampleFS(t *testing.T, dir string, rw bool) {
symlink = filepath.Join(dir, "abs")
target, err = os.Readlink(symlink)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
if target != "/a/b/c/d" {
t.Errorf("Unexpected link target: %s\n", target)
}
if rw {
// Test directory operations
test_helpers.TestRename(t, dir)

View File

@ -227,20 +227,23 @@ func TestMkdirRmdir(t *testing.T, plainDir string) {
dir := plainDir + "/dir1"
err := os.Mkdir(dir, 0777)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
err = syscall.Rmdir(dir)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
// Removing a non-empty dir should fail with ENOTEMPTY
if os.Mkdir(dir, 0777) != nil {
t.Fatal(err)
t.Error(err)
return
}
f, err := os.Create(dir + "/file")
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
f.Close()
err = syscall.Rmdir(dir)
@ -249,23 +252,26 @@ func TestMkdirRmdir(t *testing.T, plainDir string) {
t.Errorf("Should have gotten ENOTEMPTY, go %v", errno)
}
if syscall.Unlink(dir+"/file") != nil {
t.Fatal(err)
t.Error(err)
return
}
if syscall.Rmdir(dir) != nil {
t.Fatal(err)
t.Error(err)
return
}
// We should also be able to remove a directory we do not have permissions to
// read or write
err = os.Mkdir(dir, 0000)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
err = syscall.Rmdir(dir)
if err != nil {
// Make sure the directory can cleaned up by the next test run
os.Chmod(dir, 0700)
t.Fatal(err)
t.Error(err)
return
}
}
@ -275,11 +281,13 @@ func TestRename(t *testing.T, plainDir string) {
file2 := plainDir + "/rename2"
err := ioutil.WriteFile(file1, []byte("content"), 0777)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
err = syscall.Rename(file1, file2)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
syscall.Unlink(file2)
}