Skip to content

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

Open
wants to merge 100 commits into
base: main
Choose a base branch
from

Conversation

mdelapenya
Copy link
Member

@mdelapenya mdelapenya commented May 26, 2025

  • chore: deprecate GenericContainer
  • chore: migrate tests to Run
  • docs: update quickstart
  • chore: update more tests
  • chore: update more tests
  • chore(aerospike): use Run function
  • chore(socat): use Run function
  • chore: update more tests
  • chore: update tests in the wait package
  • chore: use Run in the network package
  • chore: move test to the network package
  • chore: use Run in the core
  • chore(nginx): use Run in nginx example
  • chore(modulegen): use testcontainers.Run
  • chore(azurite): use testcontainers.Run
  • break(artemis): use testcontainers.Run
  • break(eventhubs): use testcontainers.Run
  • break(arangodb): use testcontainers.Run
  • break(servicebus): use testcontainers.Run
  • chore(cassandra): use testcontainers.Run
  • chore(chroma): use testcontainers.Run
  • break(clickhouse): use testcontainers.Run
  • chore(consul): use testcontainers.Run
  • chore(couchbase): use testcontainers.Run
  • break(databend): use testcontainers.Run
  • chore(dind): use testcontainers.Run
  • break(dolt): use testcontainers.Run
  • break(dynamodb): use testcontainers.Run
  • chore(etcd): use testcontainers.Run
  • break(etcd): make options return errors
  • chore(gcloud): use testcontainers.Run in deprecated constructors
  • chore(bigquery): use testcontainers.Run
  • chore(bigtable): use testcontainers.Run
  • chore(datastore): use testcontainers.Run
  • chore(firestore): use testcontainers.Run
  • chore(pubsub): use testcontainers.Run
  • chore(spanner): use testcontainers.Run
  • chore(graafanalgtm): use testcontainers.Run
  • chore(inbucket): use testcontainers.Run
  • chore(influxdb): use testcontainers.Run
  • chore(k3s): use testcontainers.Run
  • chore(k6): use testcontainers.Run
  • break(kafka): use testcontainers.Run
  • chore(localstack): use testcontainers.Run
  • break(mariadb): use testcontainers.Run
  • break(meilisearch): use testcontainers.Run
  • chore(memcached): use testcontainers.Run
  • chore(milvus): use testcontainers.Run
  • break(minio): use testcontainers.Run
  • chore(mockserver): use testcontainers.Run
  • break(mongodb): use testcontainers.Run
  • docs(dockermodelrunner): fix comment
  • break(mssql): use testcontainers.Run
  • docs(mssql): describe MSSQL issue with negative certificates
  • chore(mssql): bump images to address the negative serial number of the certificate
  • break(mysql): use testcontainers.Run
  • break(nats): use testcontainers.Run
  • chore(neo4j): use testcontainers.Run
  • chore(openfga): use testcontainers.Run
  • break(openldap): use testcontainers.Run
  • chore(pinecone): use testcontainers.Run
  • break(postgres): use testcontainers.Run
  • chore(pulsar): use testcontainers.Run
  • chore(qdrant): use testcontainers.Run
  • break(rabbitmq): use testcontainers.Run
  • chore(rabbitmq): consistency in credentials as env vars
  • chore(redis): use testcontainers.Run
  • break(redpanda): use testcontainers.Run
  • chore(registry): use testcontainers.Run
  • chore(scylladb): use testcontainers.Run
  • fixup socat
  • chore(surrealdb): use testcontainers.Run
  • fixup socat
  • chore(toxiproxy): use testcontainers.Run
  • chore(valkey): use testcontainers.Run
  • chore(vault): use testcontainers.Run
  • chore(vearch): use testcontainers.Run
  • chore(weaviate): use testcontainers.Run
  • break(yugabyte): use testcontainers.Run
  • chore(opensearch): use testcontainers.Run

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 the GenericContainer exposed function.

For that, we needed to review all the modules, and:

  1. define an slice of moduleOptions representing the values in the original container request
  2. append all the passed-in options from the module's Run function to the moduleOpts slice
  3. check if the module consumed values from the container request to fill any state in the container: e.g. reading env vars from the container request's Env field.
  • if yes: look for an options.go file in the module with all the options, verifying there is not options struct, and a custom Option 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 new env 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.
  • if no, proceed
  1. remove the code to process the core options (e.g. testcontainers.WithEnv), as they are processed internally in the testcontainers.Run function.
  2. if the module needed a change to read from the internal options, append a new option to the 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 the Run function whenever possible. Their lint process should warn them at build/CI time.

Modules that receive a Breaking Change

  • ArangoDB
  • Artemis
  • Azure: eventhubs, servicebus
  • Clickhouse
  • Databend
  • Dolt
  • DynamoDB
  • Etcd
  • Kafka
  • MariaDB
  • Meilisearch
  • Minio
  • MongoDB
  • MSSQL
  • MySQL
  • NATS
  • OpenLDAP
  • Postgres
  • RabbitMQ
  • Redpanda
  • Yugabyte

Why is it important?

testcontainers.GenericContainer has been an important function in the library since the beginning, but we consider that having testcontainers.Run is much more idiomatic to the operations we want to do, which is no other than running a container. Also, it pairs with the docker 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.

@mdelapenya mdelapenya self-assigned this May 26, 2025
@mdelapenya mdelapenya requested a review from stevenh May 26, 2025 08:16
Copy link

netlify bot commented May 26, 2025

👷 Deploy Preview for testcontainers-go processing.

Name Link
🔨 Latest commit e1131b7
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6834234622c6f70008d582bc

Copy link

netlify bot commented May 26, 2025

Deploy Preview for testcontainers-go failed.

Name Link
🔨 Latest commit e1131b7
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6834234622c6f70008d582bc

1 similar comment
Copy link

netlify bot commented May 26, 2025

Deploy Preview for testcontainers-go failed.

Name Link
🔨 Latest commit e1131b7
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6834234622c6f70008d582bc

Copy link

netlify bot commented May 26, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 1dd29b6
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68483adcd3eb5f000816eca4
😎 Deploy Preview https://deploy-preview-3174--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mdelapenya mdelapenya changed the title break: use testcontainers.Run function everywhere chore!: use testcontainers.Run function everywhere May 26, 2025
@mdelapenya mdelapenya marked this pull request as ready for review June 4, 2025 07:52
@mdelapenya mdelapenya requested a review from a team as a code owner June 4, 2025 07:52
@mdelapenya
Copy link
Member Author

mdelapenya commented Jun 4, 2025

@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 GenericContainer function, but thinking out loud, I could split this PR in multiple batches, with 5-10 modules each, so that the last one includes the deprecation 🤔 Whatever works for you I'm happy to do so.

* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Causing compatibility issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant