Replace os.Stat with IsDir, simplifying FS abstraction.

This commit is contained in:
Jeffrey Regan
2018-07-18 11:33:30 -07:00
parent 8fda0f87ab
commit 9432671887
15 changed files with 83 additions and 69 deletions

View File

@@ -21,34 +21,25 @@ import (
"testing"
)
func TestStatNotExist(t *testing.T) {
func TestExists(t *testing.T) {
x := MakeFakeFS()
info, err := x.Stat("foo")
if info != nil {
t.Fatalf("expected nil info")
}
if err == nil {
t.Fatalf("expected error")
if x.Exists("foo") {
t.Fatalf("expected no foo")
}
}
func TestStat(t *testing.T) {
func TestIsDir(t *testing.T) {
x := MakeFakeFS()
expectedName := "my-dir"
err := x.Mkdir(expectedName, 0666)
err := x.Mkdir(expectedName)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
info, err := x.Stat(expectedName)
if err != nil {
t.Fatalf("unexpected error: %v", err)
if !x.Exists(expectedName) {
t.Fatalf(expectedName + " should exist")
}
name := info.Name()
if name != expectedName {
t.Fatalf("expected %v but got %v", expectedName, name)
}
if !info.IsDir() {
t.Fatalf("expected IsDir() return true")
if !x.IsDir(expectedName) {
t.Fatalf(expectedName + " should be a dir")
}
}
@@ -61,12 +52,8 @@ func TestCreate(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error")
}
info, err := x.Stat("foo")
if info == nil {
t.Fatalf("expected non-nil info")
}
if err != nil {
t.Fatalf("expected no error")
if !x.Exists("foo") {
t.Fatalf("expected foo to exist")
}
}