Add test for isFileExists.

This commit is contained in:
Chen Yufei
2012-12-23 14:18:34 +08:00
parent b70731dc93
commit 0f837aa8d0
2 changed files with 26 additions and 0 deletions

0
testdata/file vendored Normal file
View File

View File

@@ -73,3 +73,29 @@ func TestCopyN(t *testing.T) {
t.Error("copy len(pre)+size+len(end)<bufLen failed, got:", dst.String())
}
}
func TestIsFileExists(t *testing.T) {
exists, err := isFileExists("testdata")
if err == nil {
t.Error("should return error is path is directory")
}
if exists {
t.Error("directory should return false")
}
exists, err = isFileExists("testdata/none")
if exists {
t.Error("BOOM! You've found a non-existing file!")
}
if err != nil {
t.Error("Not existing file should just return false, on error")
}
exists, err = isFileExists("testdata/file")
if !exists {
t.Error("testdata/file exists, but returns false")
}
if err != nil {
t.Error("Why error for existing file?")
}
}