コード例 #1
0
ファイル: fval_test.go プロジェクト: walle/fval
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)
	}
}
コード例 #2
0
ファイル: fval_test.go プロジェクト: walle/fval
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)
	}
}
コード例 #3
0
ファイル: fval_test.go プロジェクト: walle/fval
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)
	}
}