-
-
Notifications
You must be signed in to change notification settings - Fork 586
fix: handle stopped containers more gracefully when reuse is enabled #3062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mdelapenya
merged 10 commits into
testcontainers:main
from
georgespalding:fix-reuse-stopped-container
Apr 25, 2025
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1666dee
fix: handle stopped containers more gracefully when reuse is enabled
georgespalding 18b92af
Merge branch 'main' into fix-reuse-stopped-container
georgespalding 1c2cd3b
Merge branch 'main' into fix-reuse-stopped-container
mdelapenya 65b7c6d
Merge branch 'main' into fix-reuse-stopped-container
mdelapenya dd03f95
fix: start container if it's not running or paused
mdelapenya 11dc36c
Merge branch 'main' into fix-reuse-stopped-container
mdelapenya e773f36
chore: proper container name
mdelapenya 63a7e56
fix: more sensible comment
mdelapenya b3bc31a
docs: add TODO comment about unpausing containers
mdelapenya 77bfbc2
chore: return an error for starting a paused container
mdelapenya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package testcontainers_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/testcontainers/testcontainers-go" | ||
| ) | ||
|
|
||
| func TestGenericContainer_stop_start_withReuse(t *testing.T) { | ||
| containerName := "my-postgres" | ||
mdelapenya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| req := testcontainers.GenericContainerRequest{ | ||
| ContainerRequest: testcontainers.ContainerRequest{ | ||
| Image: nginxAlpineImage, | ||
| ExposedPorts: []string{"8080/tcp"}, | ||
| Name: containerName, | ||
| }, | ||
| Reuse: true, | ||
| Started: true, | ||
| } | ||
|
|
||
| ctr, err := testcontainers.GenericContainer(context.Background(), req) | ||
| testcontainers.CleanupContainer(t, ctr) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, ctr) | ||
|
|
||
| err = ctr.Stop(context.Background(), nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // Run another container with same container name: | ||
| // The checks for the exposed ports must not fail when restarting the container. | ||
| ctr1, err := testcontainers.GenericContainer(context.Background(), req) | ||
| testcontainers.CleanupContainer(t, ctr1) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, ctr1) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.