-
Notifications
You must be signed in to change notification settings - Fork 892
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 #2548 from jwcesign/fix-dir-lost
karmadactl: Fix karmada-data directory not inilization isssue
- Loading branch information
Showing
2 changed files
with
51 additions
and
3 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,41 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_initializeDirectory(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
createPathInAdvance bool | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Test when there is no dir exists", | ||
createPathInAdvance: false, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Test when there is dir exists", | ||
createPathInAdvance: true, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if tt.createPathInAdvance { | ||
if err := os.MkdirAll("tmp", os.FileMode(0755)); err != nil { | ||
t.Errorf("create test directory failed in advance:%v", err) | ||
} | ||
} | ||
if err := initializeDirectory("tmp"); (err != nil) != tt.wantErr { | ||
t.Errorf("initializeDirectory() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
if err := os.RemoveAll("tmp"); err != nil { | ||
t.Errorf("clean up test directory failed after ut case:%s, %v", tt.name, err) | ||
} | ||
}) | ||
} | ||
} |