Skip to content

Conversation

@mdelapenya
Copy link
Member

@mdelapenya mdelapenya commented Oct 7, 2025

What does this PR do?

Use the Run function in mysql module

Why is it important?

Migrate modules to the new API, improving consistency and leveraging the latest testcontainers functionality.

Related issues

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

Co-Authored-By: Claude <[email protected]>
@mdelapenya mdelapenya requested a review from a team as a code owner October 7, 2025 11:46
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 7, 2025
@netlify
Copy link

netlify bot commented Oct 7, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit b22e67d
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68e4fdaf665cfa0008034910
😎 Deploy Preview https://deploy-preview-3416--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.

@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Credentials now reflect the container’s actual environment after startup.
    • Defaults username to root, overridden when MYSQL_USER is set.
    • Clearer error message when MySQL fails to start.
    • Validates that empty passwords are allowed only for the root user.
  • Refactor

    • Streamlined container startup configuration for improved reliability and consistency.
  • Tests

    • Relaxed error assertions to allow additional context around messages.

Walkthrough

Refactors MySQL module to build container options via functional customizers and use testcontainers.Run. Adds runtime credential validation, updates error text, and inspects the running container to derive and set MySQL credentials/database fields. Adjusts a test assertion to check for substring rather than exact error string.

Changes

Cohort / File(s) Summary
MySQL module refactor to Run + option customizers
modules/mysql/mysql.go
Replaces GenericContainerRequest with moduleOpts and testcontainers.Run; composes WithExposedPorts/WithEnv/WithWaitStrategy; introduces validateCreds as CustomizeRequestOption; defaults username to root, then post-run inspects env (MYSQL_USER/PASSWORD/DATABASE) to set fields; updates error message text.
Test robustness update
modules/mysql/mysql_test.go
Loosens assertion to require error substring match for non-root empty password case, tolerating additional context around the message.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant MySQL as MySQL.Run
  participant TC as testcontainers.Run
  participant C as Container
  participant Inspect as Container Inspect

  Caller->>MySQL: Run(ctx, image, opts...)
  MySQL->>MySQL: Build moduleOpts (ports, env, wait)
  MySQL->>MySQL: Attach validateCreds (CustomizeRequestOption)
  MySQL->>TC: Run(ctx, image, moduleOpts...)
  alt run failure
    TC-->>MySQL: error ("run mysql ...")
    MySQL-->>Caller: error
  else run success
    TC-->>MySQL: Container handle
    MySQL->>Inspect: Inspect / Env
    Inspect-->>MySQL: MYSQL_USER/PASSWORD/DATABASE
    MySQL->>MySQL: Update MySQLContainer fields
    MySQL-->>Caller: MySQLContainer
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • stevenh

Poem

A bunny taps the keys—hop, run, inspect—
Options bloom like clover, neatly circumspect.
Ports and env in rows align,
Secrets sniffed at startup time.
Tests now nibble subtler rhyme—
Contained, refined, and right on time. 🐇🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly captures the primary change of the pull request by indicating that the MySQL module is being updated to use the new Run function, which aligns with the core refactoring described in the diff. It is clear, specific, and free of unnecessary details or generic terms.
Description Check ✅ Passed The PR description clearly states that the mysql module will now use the Run function and aligns with the changeset summary showing replacement of the previous container initialization flow with testcontainers.Run. It explains the motivation of migrating modules to the new API for improved consistency and leveraging updated testcontainers functionality. The description also references related issues and the specific context of this change, confirming its relevance to the diff.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mdelapenya mdelapenya self-assigned this Oct 7, 2025
@mdelapenya mdelapenya merged commit d0404be into testcontainers:main Oct 7, 2025
18 checks passed
@mdelapenya mdelapenya deleted the use-run-claude-mysql branch October 7, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Changes that do not impact the existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant