Skip to content

Commit

Permalink
check for empty dir
Browse files Browse the repository at this point in the history
Signed-off-by: ntishchauhan0022 <nitishchauhan0022@gmail.com>
  • Loading branch information
nitishchauhan0022 committed Jul 23, 2023
1 parent a38d26e commit 5bf0b88
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions magefiles/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,17 @@ func Teste2eSetup() error {

// Check if .kube directory exists
if _, err := os.Stat(".kube"); err == nil {
if err := sh.Run("rmdir", ".kube"); err != nil {
fmt.Println("Error removing .kube directory:", err)
entries, err := os.ReadDir(".kube")
if err != nil {
fmt.Println("Error reading .kube directory:", err)
}
// Checking if directory is empty
if len(entries) == 0 {
if err := sh.Run("rmdir", ".kube"); err != nil {
fmt.Println("Error removing .kube directory:", err)
}
} else {
fmt.Println(".kube directory is not empty")
}
} else if os.IsNotExist(err) {
fmt.Println(".kube directory does not exist")
Expand Down

0 comments on commit 5bf0b88

Please sign in to comment.