func TestDirExistsOrCreate(t *testing.T) { tmpDir := createTmpDir(t) defer os.RemoveAll(tmpDir) path := filepath.Join(tmpDir, "test1", "test2", "test3") ok, err := fval.DirExistsOrCreate(path, 0766) if err != nil { t.Errorf("Error creating dir: %s", err) } if !ok { t.Errorf("Directory was not created") } ok, err = fval.DirExistsOrCreate(path, 0766) if err != nil { t.Errorf("Error: %s", err) } if !ok { t.Errorf("Directory did not exist") } os.Remove(path) if fval.DirExists(path) { t.Errorf("Directory %s should not exist", path) } ok, err = fval.DirExistsOrCreate(path, 0766) if err != nil { t.Errorf("Error creating dir: %s", err) } if !ok { t.Errorf("Directory was not created") } if !fval.DirExists(path) { t.Errorf("Directory %s was not created", path) } }
func TestDirExists(t *testing.T) { tmpDir := createTmpDir(t) defer os.RemoveAll(tmpDir) path := filepath.Join(tmpDir, "test") os.Mkdir(path, 0766) if !fval.DirExists(path) { t.Errorf("Did not indicate that existing directory %s exists", path) } os.Remove(path) if fval.DirExists(path) { t.Errorf("Did indicate that non existing directory %s exists", path) } os.Create(path) if fval.DirExists(path) { t.Errorf("Did indicate that file %s is a directory", path) } }
func TestDirPurgeAndCreateNoDir(t *testing.T) { tmpDir := createTmpDir(t) defer os.RemoveAll(tmpDir) path := filepath.Join(tmpDir, "test") ok, err := fval.DirPurgeAndCreate(path, 0766) if ok { t.Errorf("Should not get ok") } if err == nil { t.Errorf("Should not get no error") } if fval.DirExists(path) { t.Errorf("Directory %s should not exist", path) } }