Skip to content

Conversation

@ziggornif
Copy link

Hi,

Here's a small fix to resolve the Redis container startup issue with custom commands (#1150).

I noticed a similar issue with the redis-stack image that also overrides this.createOpts.Env.
Would you prefer I include this fix in the same PR, or should I create a separate issue to track it first?

@netlify
Copy link

netlify bot commented Oct 3, 2025

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 3e6fa91
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/68e39f9105248c000867ba9b
😎 Deploy Preview https://deploy-preview-1155--testcontainers-node.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.

@cristianrgreco
Copy link
Collaborator

Hi @ziggornif, yes please include the redis-stack command change in this PR

@cristianrgreco cristianrgreco added bug Something isn't working patch Backward compatible bug fix labels Oct 6, 2025
Same as redis image with input command

See issue testcontainers#1150
@ziggornif
Copy link
Author

Hi @cristianrgreco, I just made the modification for redis-stack as well. The REDIS_ARGS variable now contains the merge of the user's values with the default values.

I kept the current solution of creating the variable via this.withEnvironment which I recreate with the merge of both values.
We could have also edited the existing variable in this.createOpts.Env. If the current solution works for you, I'll leave it as is.

];
if (this.imageName.image.includes("redis-stack")) {
const existingRedisArgs =
(this.createOpts.Env || []).find((e) => e.startsWith("REDIS_ARGS="))?.split("=", 2)[1] || "";
Copy link
Collaborator

@cristianrgreco cristianrgreco Nov 4, 2025

Choose a reason for hiding this comment

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

Potential bug here ?.split("=", 2)[1], if the value is undefined, then calling [1] will throw TypeError, would need to be ?.[1]

Also please use ?? instead of || for specifying default values.

I would use this.environment instead of this.createOps.Env to simplify this (don't need to split strings).

// }
});

it("should start redis with custom command", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The redis containers aren't stopped at the end of the tests. Let's see if we can follow the existing await using syntax to have this handled automatically for us

const mergedRedisArgs = [existingRedisArgs, ...redisArgs].filter(Boolean).join(" ");

// remove existing REDIS_ARGS to avoid duplicates
this.createOpts.Env = (this.createOpts.Env || []).filter((e) => !e.startsWith("REDIS_ARGS="));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of directly mutating this.createOpts.Env, it would be better to invoke withEnvironment

@cristianrgreco cristianrgreco added the changes requested PR author must respond to review feedback label Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working changes requested PR author must respond to review feedback patch Backward compatible bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants