config: IsEmptyDir is true if dir doesn't exist
This commit is contained in:
parent
9689a34b28
commit
6cbadf14df
|
@ -103,6 +103,10 @@ func LoadDir(root string) (*Config, error) {
|
|||
// IsEmptyDir returns true if the directory given has no Terraform
|
||||
// configuration files.
|
||||
func IsEmptyDir(root string) (bool, error) {
|
||||
if _, err := os.Stat(root); err != nil && os.IsNotExist(err) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
fs, os, err := dirFiles(root)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
|
@ -16,6 +16,16 @@ func TestIsEmptyDir(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIsEmptyDir_noExist(t *testing.T) {
|
||||
val, err := IsEmptyDir(filepath.Join(fixtureDir, "nopenopenope"))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if !val {
|
||||
t.Fatal("should be empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsEmptyDir_noConfigs(t *testing.T) {
|
||||
val, err := IsEmptyDir(filepath.Join(fixtureDir, "dir-empty"))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue