Skip to content

Commit fcccd5c

Browse files
committed
Make image removal optional (defaults to false)
1 parent 0b6d55a commit fcccd5c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

dktest.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ func RunContext(ctx context.Context, logger Logger, imgName string, opts Options
217217
stopCtx, stopTimeoutCancelFunc := context.WithTimeout(ctx, opts.CleanupTimeout)
218218
defer stopTimeoutCancelFunc()
219219
stopContainer(stopCtx, logger, dc, c, opts.LogStdout, opts.LogStderr)
220-
removeImage(ctx, logger, dc, imgName)
220+
if opts.CleanupImage {
221+
removeImage(stopCtx, logger, dc, imgName)
222+
}
221223
}()
222224

223225
if waitContainerReady(runCtx, logger, c, opts.ReadyFunc, opts.ReadyTimeout) {

options.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ type Options struct {
1919
ReadyTimeout time.Duration
2020
// CleanupTimeout is the timeout used when stopping and removing a container
2121
CleanupTimeout time.Duration
22-
ReadyFunc func(context.Context, ContainerInfo) bool
23-
Env map[string]string
24-
Entrypoint []string
25-
Cmd []string
22+
// CleanupImage specifies whether or not the image should be removed after the test run.
23+
// If the image is used by multiple tests, you'll want to cleanup the image yourself.
24+
CleanupImage bool
25+
ReadyFunc func(context.Context, ContainerInfo) bool
26+
Env map[string]string
27+
Entrypoint []string
28+
Cmd []string
2629
// If you prefer to specify your port bindings as a string, use nat.ParsePortSpecs()
2730
PortBindings nat.PortMap
2831
PortRequired bool

0 commit comments

Comments
 (0)