feat(wait): add human-readable String() methods to all wait strategies by mdelapenya · Pull Request #3461 · testcontainers/testcontainers-go

@mdelapenya mdelapenya added the chore

Changes that do not impact the existing functionality

label

Oct 31, 2025

mdelapenya

mdelapenya

@mdelapenya @claude

Add String() method to all wait strategy types to provide human-readable
descriptions that are displayed in container lifecycle logs. This improves
the user experience by showing clear wait conditions instead of raw struct
output.

Changes:
- Add String() method to HTTPStrategy, HealthStrategy, LogStrategy,
  HostPortStrategy, FileStrategy, ExecStrategy, ExitStrategy,
  waitForSQL, MultiStrategy, NopStrategy, and TLSStrategy
- Update lifecycle logging to use strategy String() output
- Each strategy provides contextual information (ports, paths, conditions)

Example output changes:
Before: Waiting for: &{timeout:<nil> deadline:0x140001c7190 Strategies:[0x1400032e1d0]}
After: Waiting for container to be ready strategy="HTTP GET request on port 8080 path /health"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

coderabbitai[bot]

Modify ExecStrategy.String() to only show the command name and argument
count instead of full command with all arguments. This prevents sensitive
information (passwords, API tokens, credentials) from being exposed in
container lifecycle logs.

Changes:
- Show only command name when no arguments present
- Show command name with argument count when arguments present
- Never expose actual argument values

Example output:
- Before: exec command ["mysql" "-u" "root" "-pSecretPass"]
- After: exec command "mysql" with 3 arguments

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

@mdelapenya

Update container readiness logging to use structured logging format and
leverage the new String() methods on wait strategies. This provides
human-readable strategy descriptions in logs instead of raw Go struct
output.

Changes:
- Extract strategy to variable for type assertion
- Check if strategy implements fmt.Stringer interface
- Use strategy.String() for description when available
- Fall back to "unknown strategy" if String() not implemented
- Convert to structured logging with key-value pairs
- Improves log readability and parseability

Example output:
Before: ⏳ Waiting for container id abc123 image: nginx. Waiting for: &{timeout:<nil> deadline:0x140001c7190 Strategies:[0x1400032e1d0]}
After: Waiting for container to be ready containerID=abc123 image=nginx strategy="HTTP GET request on port 8080 path /health"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove special case that would omit the "all of:" prefix when only one
strategy remains after filtering nils. Always include the prefix to make
it clear that a MultiStrategy (ForAll) is being used, improving clarity
and consistency in logs.

Changes:
- Remove single-strategy special case from MultiStrategy.String()
- Always return "all of: [...]" format regardless of strategy count
- Add comment explaining the rationale

Example output:
Before: log message 'ready' (when only 1 strategy)
After: all of: [log message 'ready']

This makes it explicit that ForAll() is being used, which helps with
debugging and understanding wait behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

coderabbitai[bot]

Use proper singular/plural grammar when displaying argument count:
- "exec command 'foo'" when no arguments
- "exec command 'foo' with 1 argument" when one argument
- "exec command 'foo' with N arguments" when multiple arguments

Also adds comment explaining security consideration to avoid exposing
sensitive data in command arguments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add standard Go documentation comments to all String() method
implementations across wait strategies for better code documentation
and godoc generation.

Changes:
- Add "String returns a human-readable description of the wait strategy"
  comment to all String() methods in:
  - ExecStrategy
  - HealthStrategy
  - LogStrategy
  - HostPortStrategy
  - FileStrategy
  - ExitStrategy
  - NopStrategy
  - waitForSQL
  - TLSStrategy
  - MultiStrategy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

coderabbitai[bot]

@mdelapenya

mdelapenya added a commit that referenced this pull request

Nov 3, 2025
* main:
  chore(deps): bump github.com/docker/docker from 28.3.3+incompatible to 28.5.1+incompatible (#3464)
  feat(wait): add human-readable String() methods to all wait strategies (#3461)
  chore(deps): bump mkdocs-include-markdown-plugin from 7.1.6 to 7.2.0 (#3463)
  chore(deps): bump actions/setup-go from 5.4.0 to 6.0.0 (#3462)