Skip to content

feat!: add options when creating RawCommand #3168

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

Conversation

benja-M-1
Copy link
Contributor

What does this PR do?

This PR adds a second optional parameter to the testcontainers.NewRawCommand function to pass executable options to it.

Why is it important?

This allows any startup command to be ran with options like a different user, working directory and any available executable option.

For example:

testcontainers.Run(
	context.Background(),
	"rust:latest",
	tc.WithEntrypoint("tail"),
	tc.WithCmd("-f", "/dev/null"),
	tc.WithConfigModifier(func(c *container.Config) {
		c.WorkingDir = "/tmp"
	}),
	tc.WithStartupCommand(
		// This creates the /tmp/hello_world directory
		NewExecCommand([]string{"cargo", "new", "hello_world", "--vcs", "none"}),
		// This will add a dependency executing cargo from /tmp/hello_world
		NewExecCommand([]string{"cargo", "add", "rand"}, tcexec.WithWorkingDir("/tmp/hello_world")),
		NewExecCommand([]string{"cargo", "build"}, tcexec.WithWorkingDir("/tmp/hello_world")),
	),
	tc.WithWaitStrategy(wait.ForAll(
		wait.ForFile("/tmp/hello_world/target/debug/hello_world"),
	)),

Related issues

Copy link

netlify bot commented May 22, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit b83e0c0
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/682f735e5bc6fb0008f3c20c
😎 Deploy Preview https://deploy-preview-3168--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.

@benja-M-1 benja-M-1 marked this pull request as ready for review May 22, 2025 16:16
@benja-M-1 benja-M-1 requested a review from a team as a code owner May 22, 2025 16:16
@mdelapenya mdelapenya changed the title feat: Add options when creating RawCommand feat: add options when creating RawCommand May 22, 2025
@benja-M-1 benja-M-1 force-pushed the feat/add-options-to-rawcommand branch from 94748f2 to b83e0c0 Compare May 22, 2025 18:56
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

As we discussed, this is a very light BC, so I'm changing the title to feat!.

Other than that, LGTM, thanks for your time here!

@mdelapenya mdelapenya self-assigned this Jun 2, 2025
@mdelapenya mdelapenya added the breaking change Causing compatibility issues. label Jun 2, 2025
@mdelapenya mdelapenya changed the title feat: add options when creating RawCommand feat!: add options when creating RawCommand Jun 2, 2025
@mdelapenya mdelapenya merged commit 3f9e80d into testcontainers:main Jun 2, 2025
398 of 399 checks passed
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Jun 3, 2025
* 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)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Jun 3, 2025
* main: (236 commits)
  feat(kafka,redpanda): support for waiting for mapped ports without external checks (testcontainers#3165)
  chore: bump ryuk to 0.12.0 (testcontainers#3195)
  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)
  docs(options): refactor options layout in modules (testcontainers#3163)
  fix(ci): do not run sonar for Testcontainers Cloud (testcontainers#3166)
  chore(ci): do not fail fast in the Testcontainers Cloud run (testcontainers#3164)
  feat: support adding wait strategies as functional option (testcontainers#3161)
  fix(etcd): expose ports for the etcd nodes (testcontainers#3162)
  fix(wait): no port to wait for (testcontainers#3158)
  feat: add more functional options for customising containers (testcontainers#3156)
  docs(redpanda): update sasl authentication option to use scram sha 256 (testcontainers#3126)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3137)
  chore(deps): bump github.com/shirou/gopsutil/v4 from 4.25.1 to 4.25.4 (testcontainers#3133)
  chore(deps): bump github.com/docker/docker from 28.0.1+incompatible to 28.1.1+incompatible (testcontainers#3152)
  feat(memcached): add memcached module (testcontainers#3132)
  fix(etcd): single node etcd cluster access (testcontainers#3149)
  feat(valkey): add TLS support for Valkey (testcontainers#3131)
  ...
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.

2 participants