Skip to content

Commit

Permalink
Make image removal optional (defaults to false)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhui committed Apr 15, 2024
1 parent 0b6d55a commit fcccd5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ func RunContext(ctx context.Context, logger Logger, imgName string, opts Options
stopCtx, stopTimeoutCancelFunc := context.WithTimeout(ctx, opts.CleanupTimeout)
defer stopTimeoutCancelFunc()
stopContainer(stopCtx, logger, dc, c, opts.LogStdout, opts.LogStderr)
removeImage(ctx, logger, dc, imgName)
if opts.CleanupImage {
removeImage(stopCtx, logger, dc, imgName)
}
}()

if waitContainerReady(runCtx, logger, c, opts.ReadyFunc, opts.ReadyTimeout) {
Expand Down
11 changes: 7 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ type Options struct {
ReadyTimeout time.Duration
// CleanupTimeout is the timeout used when stopping and removing a container
CleanupTimeout time.Duration
ReadyFunc func(context.Context, ContainerInfo) bool
Env map[string]string
Entrypoint []string
Cmd []string
// CleanupImage specifies whether or not the image should be removed after the test run.
// If the image is used by multiple tests, you'll want to cleanup the image yourself.
CleanupImage bool
ReadyFunc func(context.Context, ContainerInfo) bool
Env map[string]string
Entrypoint []string
Cmd []string
// If you prefer to specify your port bindings as a string, use nat.ParsePortSpecs()
PortBindings nat.PortMap
PortRequired bool
Expand Down

0 comments on commit fcccd5c

Please sign in to comment.