Skip to content
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

[Enhancement]: Reuse flag for module Postgres #2726

Open
comerc opened this issue Aug 9, 2024 · 7 comments · May be fixed by #2768
Open

[Enhancement]: Reuse flag for module Postgres #2726

comerc opened this issue Aug 9, 2024 · 7 comments · May be fixed by #2768
Labels
enhancement New feature or request

Comments

@comerc
Copy link

comerc commented Aug 9, 2024

Proposal

Like GenericContainerRequest:

genericContainerReq := testcontainers.GenericContainerRequest{
  ContainerRequest: req,
  Started:          true,
  Logger:           logger,
  Reuse:            true,
}
@comerc comerc added the enhancement New feature or request label Aug 9, 2024
@comerc comerc closed this as completed Aug 9, 2024
@comerc
Copy link
Author

comerc commented Aug 9, 2024

I still need the setupBaseDatabase() function in Singletone, so I don't need the flag.

@comerc
Copy link
Author

comerc commented Aug 12, 2024

OK, we have .WithInitScripts() for initialization.

Then the feature request is relevant again.

@comerc comerc reopened this Aug 12, 2024
@mdelapenya
Copy link
Member

Hi @comerc so you'd see valuable having a WithReuse functional option for all modules, not for Postgres only, right?

@stevenh
Copy link
Collaborator

stevenh commented Aug 13, 2024

This can already be easily achieved using testcontainers.CustomizeRequestOption for example:

	reuse := testcontainers.CustomizeRequestOption(
		func(req *testcontainers.GenericContainerRequest) error {
			req.Reuse = true
			return nil
		},
	)
	postgress.Run(ctx, "docker.io/postgres:16-alpine", reuse)

@mdelapenya
Copy link
Member

mdelapenya commented Aug 13, 2024

please remember that we'd also need the container name for reuse (see https://golang.testcontainers.org/features/creating_container/#reusable-container):

	reuse := testcontainers.CustomizeRequestOption(
		func(req *testcontainers.GenericContainerRequest) error {
			req.Reuse = true
			req.Name = "my-container-name"
			return nil
		},
	)
	postgress.Run(ctx, "docker.io/postgres:16-alpine", reuse)

@mdelapenya
Copy link
Member

@comerc given there is a way to customise the request with Reuse, I think you can make progress. I'd appreciate your feedback about that and with that feedback evaluate if a specific functional option is needed for that.

Thanks!

@mdelapenya mdelapenya linked a pull request Sep 4, 2024 that will close this issue
@mdelapenya
Copy link
Member

I think #2768 will solve this. Would appreciate your review 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants