Skip to content

Commit

Permalink
Ensure container removed in test helpers
Browse files Browse the repository at this point in the history
* Fixes flaky clear cache tests

Signed-off-by: Matthew McNew <mmcnew@pivotal.io>
Signed-off-by: Emily Casey <ecasey@pivotal.io>
  • Loading branch information
matthewmcnew authored and ekcasey committed Jan 7, 2019
1 parent 7646471 commit a1a1a0e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/buildpack/lifecycle"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
dockercontainer "github.com/docker/docker/api/types/container"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
Expand Down Expand Up @@ -856,13 +857,18 @@ func runInImage(t *testing.T, dockerCli *docker.Client, volumes []string, repoNa
Binds: volumes,
}, nil, "")
h.AssertNil(t, err)
defer dockerCli.ContainerRemove(ctx, ctr.ID, dockertypes.ContainerRemoveOptions{Force: true})
okChan, errChan := dockerCli.ContainerWait(ctx, ctr.ID, container.WaitConditionRemoved)

var buf bytes.Buffer
err = dockerCli.RunContainer(ctx, ctr.ID, &buf, &buf)
if err != nil {
t.Fatalf("Expected nil: %s", errors.Wrap(err, buf.String()))
}

select {
case <-okChan:
case err = <-errChan:
h.AssertNil(t, err)
}
return buf.String()
}

0 comments on commit a1a1a0e

Please sign in to comment.