posix: test isDirEmpty, change error conditional (#4743)

This commit adds a new test for isDirEmpty (for code coverage) and
changes around the error conditional. Previously, there was a `return
nil` statement that would only be triggered under a race condition and
would trip up our test coverage for no real reason. With this new error
conditional, there's no awkward 'else'-esque condition, which means test
coverage will not change between runs for no reason in this specific
test. It's also a cleaner read.
This commit is contained in:
Brendan Ashworth
2017-08-04 10:43:51 -07:00
committed by Dee Koder
parent fcc61fa46a
commit 28bc5899fd
2 changed files with 44 additions and 12 deletions

View File

@@ -73,6 +73,42 @@ func TestPosixGetDiskInfo(t *testing.T) {
}
}
func TestPosixIsDirEmpty(t *testing.T) {
tmp, err := ioutil.TempDir(globalTestTmpDir, "minio-")
if err != nil {
t.Fatal(err)
}
defer removeAll(tmp)
// Should give false on non-existent directory.
dir1 := slashpath.Join(tmp, "non-existent-directory")
if isDirEmpty(dir1) != false {
t.Error("expected false for non-existent directory, got true")
}
// Should give false for not-a-directory.
dir2 := slashpath.Join(tmp, "file")
err = ioutil.WriteFile(dir2, []byte("hello"), 0777)
if err != nil {
t.Fatal(err)
}
if isDirEmpty(dir2) != false {
t.Error("expected false for a file, got true")
}
// Should give true for a real empty directory.
dir3 := slashpath.Join(tmp, "empty")
err = os.Mkdir(dir3, 0777)
if err != nil {
t.Fatal(err)
}
if isDirEmpty(dir3) != true {
t.Error("expected true for empty dir, got false")
}
}
// TestPosixReadAll - TestPosixs the functionality implemented by posix ReadAll storage API.
func TestPosixReadAll(t *testing.T) {
// create posix test setup