From 12a8722001f8ed14adf0b695ee7ad9e5e745da59 Mon Sep 17 00:00:00 2001 From: moogacs Date: Thu, 2 Jan 2025 08:25:30 +0100 Subject: [PATCH] move docs to garbage_collector/#terminate-function --- docs/features/common_functional_options.md | 38 --------------------- docs/features/garbage_collector.md | 39 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/docs/features/common_functional_options.md b/docs/features/common_functional_options.md index 23e33c929c..18d0e4b007 100644 --- a/docs/features/common_functional_options.md +++ b/docs/features/common_functional_options.md @@ -165,41 +165,3 @@ The above example is updating the predefined command of the image, **appending** !!!info This can't be used to replace the command, only to append options. - -#### NewTerminateOptions - -- Since testcontainers-go :material-tag: v0.35.0 - -If you want to attach option to container termination, you can use the `testcontainer.NewTerminateOptions(ctx context.Context, opts ...TerminateOption) *TerminateOptions` option, which receives a TerminateOption as parameter, creating custom termination options to be passed on the container termination. - -##### Terminate Options - -###### [StopContext](../../cleanup.go) -Sets the context for the Container termination. - -- **Function**: `StopContext(ctx context.Context) TerminateOption` -- **Default**: The context passed in `Terminate()` -- **Usage**: -```go -err := container.Terminate(ctx,StopContext(context.Background())) -``` - -###### [StopTimeout](../../cleanup.go) -Sets the timeout for stopping the Container. - -- **Function**: ` StopTimeout(timeout time.Duration) TerminateOption` -- **Default**: 10 seconds -- **Usage**: -```go -err := container.Terminate(ctx, StopTimeout(20 * time.Second)) -``` - -###### [RemoveVolumes](../../cleanup.go) -Sets the volumes to be removed during Container termination. - -- **Function**: ` RemoveVolumes(volumes ...string) TerminateOption` -- **Default**: Empty (no volumes removed) -- **Usage**: -```go -err := container.Terminate(ctx, RemoveVolumes("vol1", "vol2")) -``` diff --git a/docs/features/garbage_collector.md b/docs/features/garbage_collector.md index e725f5a9bd..aab0e56ce3 100644 --- a/docs/features/garbage_collector.md +++ b/docs/features/garbage_collector.md @@ -17,6 +17,45 @@ The primary method is to use the `Terminate(context.Context)` function that is available when a container is created. Use `defer` to ensure that it is called on test completion. +#### NewTerminateOptions + +- Since testcontainers-go :material-tag: v0.35.0 + +If you want to attach option to container termination, you can use the `testcontainer.NewTerminateOptions(ctx context.Context, opts ...TerminateOption) *TerminateOptions` option, which receives a TerminateOption as parameter, creating custom termination options to be passed on the container termination. + +##### Terminate Options + +###### [StopContext](../../cleanup.go) +Sets the context for the Container termination. + +- **Function**: `StopContext(ctx context.Context) TerminateOption` +- **Default**: The context passed in `Terminate()` +- **Usage**: +```go +err := container.Terminate(ctx,StopContext(context.Background())) +``` + +###### [StopTimeout](../../cleanup.go) +Sets the timeout for stopping the Container. + +- **Function**: ` StopTimeout(timeout time.Duration) TerminateOption` +- **Default**: 10 seconds +- **Usage**: +```go +err := container.Terminate(ctx, StopTimeout(20 * time.Second)) +``` + +###### [RemoveVolumes](../../cleanup.go) +Sets the volumes to be removed during Container termination. + +- **Function**: ` RemoveVolumes(volumes ...string) TerminateOption` +- **Default**: Empty (no volumes removed) +- **Usage**: +```go +err := container.Terminate(ctx, RemoveVolumes("vol1", "vol2")) +``` + + !!!tip Remember to `defer` as soon as possible so you won't forget. The best time