mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
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
|
// IsEmptyDir returns true if the directory given has no Terraform
|
||||||
// configuration files.
|
// configuration files.
|
||||||
func IsEmptyDir(root string) (bool, error) {
|
func IsEmptyDir(root string) (bool, error) {
|
||||||
|
if _, err := os.Stat(root); err != nil && os.IsNotExist(err) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
fs, os, err := dirFiles(root)
|
fs, os, err := dirFiles(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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) {
|
func TestIsEmptyDir_noConfigs(t *testing.T) {
|
||||||
val, err := IsEmptyDir(filepath.Join(fixtureDir, "dir-empty"))
|
val, err := IsEmptyDir(filepath.Join(fixtureDir, "dir-empty"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user