-
-
Notifications
You must be signed in to change notification settings - Fork 546
chore!: use testcontainers.Run function everywhere #3174
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
base: main
Are you sure you want to change the base?
Conversation
👷 Deploy Preview for testcontainers-go processing.
|
❌ Deploy Preview for testcontainers-go failed.
|
1 similar comment
❌ Deploy Preview for testcontainers-go failed.
|
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
* main: feat!: add options when creating RawCommand (testcontainers#3168) chore(deps)!: bump github.com/docker/docker from 28.1.1+incompatible to 28.2.2+incompatible (testcontainers#3194) feat(couchbase): adding auth to couchbase initCluster functions to support container reuse (testcontainers#3048) chore(deps): bump github.com/containerd/containerd/v2 (testcontainers#3167)
* main: chore: bump ryuk to 0.12.0 (testcontainers#3195)
* main: fix: workaround for moby/moby#50133 when reusing container in testcontainers.GenericContainer. (testcontainers#3197) feat(kafka,redpanda): support for waiting for mapped ports without external checks (testcontainers#3165)
@stevenh I think this is ready to review. I know it's a large one, but it applies consistently all the changes commit by commit. I decided to send it in one single PR instead of multiple ones because I'm deprecating the |
* main: fix: use PortEndpoint() in a few more modules (testcontainers#3203) fix: try to fix more IPv6 handling issues (testcontainers#3198) chore!: do not wait for all the exposed ports to be ready (testcontainers#3199)
What does this PR do?
It applies the recently added
testcontainers.Run
function in the core and in all the modules, deprecating the usage of theGenericContainer
exposed function.For that, we needed to review all the modules, and:
moduleOptions
representing the values in the original container requestmoduleOpts
sliceoptions
struct, and a customOption
type representing the module's own customisation types. If that struct and the Option type existed, we added a map[string]string for the env vars, changing all the existing options that could set env vars into the container request, into an Option type writing the passed-in values to the newenv
field in the options. Why? Because with this new approach, the module has no access to the container request within the scope of the Run method, so we need to change the functional opts and read those env vars from the options instead. The module's Run function now has to loop through the passed-in options and apply its own options.testcontainers.WithEnv
), as they are processed internally in thetestcontainers.Run
function.moduleOptions
.The result is that the
testcontainers.Run
function receives a slice of core options.This is considered a breaking change, as for those modules where we changed the existing options to the new custom type, the function signature changed. In practice, users that simply passed the options to the Run function has nothing to change, but we acknowledge that there could be users that are assigning these options to a variable, and here they will receive the breaking change. This could happen mostly in tests and test tables.
Apart from this, we noticed that several modules had their internal
Option
type not returning errors, which was not consistent for our pattern to validate the options. Given this PR is already a BC for many modules, we took the chance to update those modules' options to return error, causing another breaking change.The first commit in this PR is deprecating the
GenericContainer
function, so consumer would need to update to theRun
function whenever possible. Their lint process should warn them at build/CI time.Modules that receive a Breaking Change
Why is it important?
testcontainers.GenericContainer
has been an important function in the library since the beginning, but we consider that havingtestcontainers.Run
is much more idiomatic to the operations we want to do, which is no other than running a container. Also, it pairs with thedocker run
command.With the addition of functional options for all the container request fields, we consider it's now possible to even deprecate the struct, move it to an internal package in the library, and always customise containers through the functional options APIs.