fix tmpdir creation

This commit is contained in:
Adrien Delorme 2021-02-11 15:17:05 +01:00
parent 021044e963
commit ad0ce49cec
2 changed files with 8 additions and 11 deletions

View File

@ -213,8 +213,8 @@ func TestInitCommand_Run(t *testing.T) {
}
}`,
},
cfg.dir("3_pkr_config"),
cfg.dir("3_pkr_user_folder"),
cfg.dir("4_pkr_config"),
cfg.dir("4_pkr_user_folder"),
1,
nil,
"h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
@ -223,6 +223,12 @@ func TestInitCommand_Run(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Cleanup(func() {
_ = os.RemoveAll(tt.packerConfigDir)
})
t.Cleanup(func() {
_ = os.RemoveAll(tt.packerUserFolder)
})
for _, init := range tt.init {
init(t, tt)
if t.Skipped() {
@ -231,13 +237,7 @@ func TestInitCommand_Run(t *testing.T) {
}
log.Printf("starting %s", tt.name)
createFiles(tt.packerConfigDir, tt.inPluginFolder)
t.Cleanup(func() {
_ = os.RemoveAll(tt.packerConfigDir)
})
createFiles(tt.packerUserFolder, tt.inConfigFolder)
t.Cleanup(func() {
_ = os.RemoveAll(tt.packerUserFolder)
})
hash, err := dirhash.HashDir(tt.packerConfigDir, "", dirhash.DefaultHash)
if err != nil {

View File

@ -15,9 +15,6 @@ func mustString(s string, e error) string {
}
func createFiles(dir string, content map[string]string) {
if err := os.MkdirAll(dir, 0777); err != nil {
panic(err)
}
for relPath, content := range content {
contentPath := filepath.Join(dir, relPath)
if err := os.MkdirAll(filepath.Dir(contentPath), 0777); err != nil {