Skip to content

Commit

Permalink
validation/util/container: Remove bundle even if delete fails
Browse files Browse the repository at this point in the history
When the container failed in creation, delete will fail, but we still
want to remove the test bundle directory.

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Nov 30, 2017
1 parent 90c6a76 commit 87af1d1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion validation/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
if err != nil {
util.Fatal(err)
}
defer r.Clean(true)
defer r.Clean(true, true)

err = r.SetConfig(&g)
if err != nil {
Expand Down
19 changes: 11 additions & 8 deletions validation/util/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,19 @@ func (r *Runtime) Delete() error {
return cmd.Run()
}

// Clean deletes the container and removes the bundle file according to the input parameter
func (r *Runtime) Clean(removeBundle bool) error {
// Clean deletes the container. If removeBundle is set, the bundle
// directory is removed after the container is deleted succesfully or, if
// forceRemoveBundle is true, after the deletion attempt regardless of
// whether it was successful or not.
func (r *Runtime) Clean(removeBundle bool, forceRemoveBundle bool) error {
err := r.Delete()
if err != nil {
return err
}

if removeBundle {
os.RemoveAll(r.BundleDir)
if removeBundle && (err == nil || forceRemoveBundle) {
err2 := os.RemoveAll(r.BundleDir)
if err2 != nil && err == nil {
err = err2
}
}

return nil
return err
}
2 changes: 1 addition & 1 deletion validation/util/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func RuntimeInsideValidate(g *generate.Generator, f PreFunc) (err error) {
os.RemoveAll(bundleDir)
return err
}
defer r.Clean(true)
defer r.Clean(true, true)
err = r.SetConfig(g)
if err != nil {
return err
Expand Down

0 comments on commit 87af1d1

Please sign in to comment.