-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #687 from mskwon/20230707-cleanDir
backup: Return nil error for delete of nonexistent directory
- Loading branch information
Showing
2 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package backup | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
) | ||
|
||
func TestCleanDir(t *testing.T) { | ||
t.Run("Test deletion of nonexistent directory", | ||
func(t *testing.T) { | ||
b := &Backuper{} | ||
|
||
dir := path.Join(t.TempDir(), t.Name(), "does-not-exist") | ||
if err := b.cleanDir(dir); err != nil { | ||
t.Fatalf("unexpected error when deleting nonexistent dir: %v", err) | ||
} | ||
}, | ||
) | ||
|
||
t.Run("Test deletion of existing directory", | ||
func(t *testing.T) { | ||
b := &Backuper{} | ||
|
||
dir := t.TempDir() | ||
if err := os.MkdirAll(dir, 0644); err != nil { | ||
t.Fatalf("unexpected error while creating temporary directory: %v", err) | ||
} | ||
if err := b.cleanDir(dir); err != nil { | ||
t.Fatalf("unexpected error while deleting existing dir: %v", err) | ||
} | ||
if err := b.cleanDir(dir); err != nil { | ||
t.Fatalf("unexpected error during back to back invocation of delete: %v", err) | ||
} | ||
}, | ||
) | ||
} |