Add removeAll to fakeFs

This commit is contained in:
jregan
2018-11-22 06:50:43 -08:00
parent 621ed52bab
commit eed16afb00
4 changed files with 52 additions and 6 deletions

View File

@@ -40,14 +40,41 @@ func TestIsDir(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !x.Exists(expectedName) {
t.Fatalf(expectedName + " should exist")
}
shouldExist(t, x, expectedName)
if !x.IsDir(expectedName) {
t.Fatalf(expectedName + " should be a dir")
}
}
func shouldExist(t *testing.T, fs FileSystem, name string) {
if !fs.Exists(name) {
t.Fatalf(name + " should exist")
}
}
func shouldNotExist(t *testing.T, fs FileSystem, name string) {
if fs.Exists(name) {
t.Fatalf(name + " should not exist")
}
}
func TestRemoveAll(t *testing.T) {
x := MakeFakeFS()
x.WriteFile("/foo/project/file.yaml", []byte("Unused"))
x.WriteFile("/foo/project/subdir/file.yaml", []byte("Unused"))
x.WriteFile("/foo/apple/subdir/file.yaml", []byte("Unused"))
shouldExist(t, x, "/foo/project/file.yaml")
shouldExist(t, x, "/foo/project/subdir/file.yaml")
shouldExist(t, x, "/foo/apple/subdir/file.yaml")
err := x.RemoveAll("/foo/project")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
shouldNotExist(t, x, "/foo/project/file.yaml")
shouldNotExist(t, x, "/foo/project/subdir/file.yaml")
shouldExist(t, x, "/foo/apple/subdir/file.yaml")
}
func TestIsDirDeeper(t *testing.T) {
x := MakeFakeFS()
x.WriteFile("/foo/project/file.yaml", []byte("Unused"))
@@ -78,9 +105,7 @@ func TestCreate(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error")
}
if !x.Exists("foo") {
t.Fatalf("expected foo to exist")
}
shouldExist(t, x, "foo")
}
func TestReadFile(t *testing.T) {