Skip to content

feat: add more functional options to the modules API #3070

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
merged 19 commits into from
Apr 11, 2025

Conversation

mdelapenya
Copy link
Member

  • chore: deprecate request fields that can be modified by the existing modifiers
  • feat: add the missing functional options for the container request
  • chore: refactor option tests to follow the test helper function pattern
  • docs: document new functional options
  • chore: do not use postgres in functional options docs
  • chore(localstack): use new customisers instead of the override
  • chore: apply deprecations

What does this PR do?

This PR adds the missing functional options to the modules API:

  • testcontainers.WithExposedPort(ports ...string)
  • testcontainers.WithEntrypoint(entrypoint ...string)
  • testcontainers.WithCmd(cmd ...string)
  • testcontainers.WithLabels(labels map[string]string)
  • testcontainers.WithFiles(files ...testcontainers.ContainerFile)
  • testcontainers.WithMounts(mounts ...testcontainers.ContainerMount)
  • testcontainers.WithTmpfs(tmpfs map[string]string)

At the same time, it deprecates some fields of the ContainerRequest that won't be used anymore, but instead should be configured using the proper ConfigModifier:

  • Hostname: use the req.ConfigModifier instead
  • WorkingDir: use the req.ConfigModifier instead
  • Privileged: use the req.HostConfigModifier instead
  • User: use the req.ConfigModifier instead
  • ShmSize: use the req.HostConfigModifier instead

The usage of those fields has been updated across the library, and the default config modifiers has been updated to support passing those values in the case the client code stil uses the deprecated fields.

All options has been added to the docs.

Why is it important?

Keep the basic creation of containers simple, delegating advanced features to the modifiers. Also adding all supported fields as functional options makes the modules API feature complete in terms of customisation, making the override container request option not needed for common use cases.

Follow-ups

I'm thinking about creating a GenericContainer new module, which is able to consume all the options as any other module, therefore, the core library would just be the foundation for intearacting with the docker engine, and the modules would be the real meat for Testcontainers users.

@mdelapenya mdelapenya requested a review from a team as a code owner March 31, 2025 12:56
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Mar 31, 2025
@mdelapenya mdelapenya self-assigned this Mar 31, 2025
@mdelapenya mdelapenya requested a review from stevenh March 31, 2025 12:56
Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 54cb074
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/67f8b0cda2b2a90008f6aaf4
😎 Deploy Preview https://deploy-preview-3070--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 site configuration.

@@ -334,3 +334,69 @@ func WithWaitStrategyAndDeadline(deadline time.Duration, strategies ...wait.Stra
return nil
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case there is a discussion about variadic Vs single arguments in the new options, I left a comment here: #3071 (comment)

Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the consistency improvement, just a few suggestions

@mdelapenya mdelapenya requested a review from stevenh April 1, 2025 14:16
* main:
  chore(deps): bump docker/setup-docker-action from 4.2.0 to 4.3.0 (testcontainers#3077)
  chore(deps): bump github/codeql-action from 3.28.12 to 3.28.13 (testcontainers#3078)
  chore(deps): bump tj-actions/changed-files from 45.0.4 to 46.0.3 (testcontainers#3076)
  docs: add dependabot configuration (testcontainers#3074)
  chore(deps): replace `golang.org/x/exp/slices` with stdlib (testcontainers#3075)
  fix(dind): use docker image load (testcontainers#3073)
* main:
  fix(mssql): reduce flakiness in tests (testcontainers#3084)
  chore: bump golangci-lint to v2 (testcontainers#3082)
  chore(gcloud): deprecate old gcp containers, creating subpackages for them (testcontainers#3063)
  fix(mongodb): replica set initialization & connection handling (testcontainers#2984)
Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, concerned about a few which are appending when I would expect to replace due to how they work.

Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mdelapenya mdelapenya merged commit 5a0b15b into testcontainers:main Apr 11, 2025
193 checks passed
@mdelapenya mdelapenya deleted the all-options branch April 11, 2025 09:09
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Apr 11, 2025
* main:
  security(compose): upgrade github.com/docker/compose/v2 to fix security vulnerability (testcontainers#3095)
  feat: add more functional options to the modules API (testcontainers#3070)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Apr 14, 2025
* main: (91 commits)
  chore(deps): bump github/codeql-action from 3.28.13 to 3.28.15 (testcontainers#3097)
  chore(deps): bump golang.org/x/crypto from 0.31.0 to 0.37.0 (testcontainers#3098)
  feat(aerospike): add Aerospike module (testcontainers#3094)
  security(compose): upgrade github.com/docker/compose/v2 to fix security vulnerability (testcontainers#3095)
  feat: add more functional options to the modules API (testcontainers#3070)
  chore(deps): bump golang.org/x/net in /modules/arangodb (testcontainers#3087)
  feat: add arangodb module (testcontainers#3083)
  chore(deps): bump actions/upload-artifact from 4.6.0 to 4.6.2 (testcontainers#3086)
  chore(deps): bump SonarSource/sonarqube-scan-action from 5.0.0 to 5.1.0 (testcontainers#3085)
  feat: add socat container (testcontainers#3071)
  fix(mssql): reduce flakiness in tests (testcontainers#3084)
  chore: bump golangci-lint to v2 (testcontainers#3082)
  chore(gcloud): deprecate old gcp containers, creating subpackages for them (testcontainers#3063)
  fix(mongodb): replica set initialization & connection handling (testcontainers#2984)
  chore(deps): bump docker/setup-docker-action from 4.2.0 to 4.3.0 (testcontainers#3077)
  chore(deps): bump github/codeql-action from 3.28.12 to 3.28.13 (testcontainers#3078)
  chore(deps): bump tj-actions/changed-files from 45.0.4 to 46.0.3 (testcontainers#3076)
  docs: add dependabot configuration (testcontainers#3074)
  chore(deps): replace `golang.org/x/exp/slices` with stdlib (testcontainers#3075)
  fix(dind): use docker image load (testcontainers#3073)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants