Skip to content

Conversation

@mdelapenya
Copy link
Member

  • chore(dolt): use Run function
  • chore: deprecate option

What does this PR do?

Use Run function in the Dolt module, deprecating an option that should be internal.

Why is it important?

Migrate modules to the new API

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner October 2, 2025 12:14
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 2, 2025
@mdelapenya mdelapenya self-assigned this Oct 2, 2025
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 2, 2025
@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 50f01de
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68de71f42fe2ce0008d3ab79
😎 Deploy Preview https://deploy-preview-3405--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 2, 2025

Summary by CodeRabbit

  • New Features

    • Automatic credential discovery after container start, with sensible defaults when running as root.
    • Automatic database and user initialization based on discovered credentials.
    • Added runtime validation: returns an error if a non-root user has an empty password.
  • Chores

    • Introduced a deprecated helper for default credentials to maintain compatibility.

Walkthrough

Refactors the Dolt module to use testcontainers.Run with assembled options, defers credential handling to post-start Inspect, adds default-credential helper (public deprecated + private), validates discovered credentials at runtime, and conditionally initializes database/user after container start.

Changes

Cohort / File(s) Summary
Dolt module runtime & credential flow
modules/dolt/dolt.go
Replace direct ContainerRequest construction with testcontainers.Run using moduleOpts (WithExposedPorts/WithEnv/WithWaitStrategy). Add private withDefaultCredentials and deprecated public WithDefaultCredentials() helper. Append default-credential option to run opts, perform post-run Inspect to discover username/password/database, default to root when absent, validate that non-root users have a password, and initialize DB/user when createUser is true. Retain RunContainer alias to Run.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Dolt as Dolt module
  participant TC as testcontainers
  participant C as Container
  participant DB as Dolt DB init

  Caller->>Dolt: Run(ctx, opts...)
  Dolt->>Dolt: Build moduleOpts (WithExposedPorts, WithEnv, WithWaitStrategy)
  Dolt->>Dolt: Append user opts + withDefaultCredentials
  Dolt->>TC: Run(ctx, image, moduleOpts)
  TC-->>Dolt: Container handle (C)

  rect rgba(230,245,255,0.5)
  note right of Dolt: Post-start credential discovery
  Dolt->>C: Inspect -> env
  Dolt->>Dolt: Derive user/password/database (default to root if missing)
  end

  alt user != root AND password == ""
    Dolt-->>Caller: error (missing password for non-root user)
  else createUser == true
    rect rgba(240,255,240,0.6)
    note over Dolt,DB: Conditional initialization
    Dolt->>DB: Create database if missing
    Dolt->>DB: Create user & grant permissions
    end
    Dolt-->>Caller: DoltContainer (with populated credentials)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

In a dolty dock I thump my feet, 🐰
I spin a container, tidy and neat.
I peek inside to learn the key,
If root’s the owner, password’s free.
Else I make user, grant, then go—hop, hop, deploy!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately captures the primary change by indicating that the Dolt module now uses the Run function, which aligns with the PR’s main objective of migrating to the new API and deprecating the old option.
Description Check ✅ Passed The description clearly outlines the PR’s purpose to use the Run function in the Dolt module and deprecate an internal option, which directly corresponds to the implemented changes and migration to the new API.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16b1d77 and d068e01.

📒 Files selected for processing (1)
  • modules/dolt/dolt.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/dolt/dolt.go (4)
modules/mysql/mysql.go (2)
  • WithDefaultCredentials (29-45)
  • Run (54-105)
options.go (5)
  • CustomizeRequestOption (28-28)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithEnv (75-85)
  • WithWaitStrategy (366-368)
modules/consul/consul.go (1)
  • Run (61-83)
container.go (1)
  • Container (41-73)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
modules/dolt/dolt.go (1)

106-108: Simplify redundant password checks.

The condition len(dc.password) == 0 && dc.password == "" is redundant since both checks are equivalent in Go. Consider simplifying to just dc.password == "".

Apply this diff:

-	if len(dc.password) == 0 && dc.password == "" && !strings.EqualFold(rootUser, dc.username) {
+	if dc.password == "" && !strings.EqualFold(rootUser, dc.username) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d068e01 and 50f01de.

📒 Files selected for processing (1)
  • modules/dolt/dolt.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/dolt/dolt.go (4)
modules/mysql/mysql.go (2)
  • WithDefaultCredentials (29-45)
  • Run (54-105)
options.go (5)
  • CustomizeRequestOption (28-28)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithEnv (75-85)
  • WithWaitStrategy (366-368)
modules/clickhouse/clickhouse.go (1)
  • Run (69-123)
container.go (1)
  • Container (41-73)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint (modules/dolt) / lint: modules/dolt
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
modules/dolt/dolt.go (4)

30-33: LGTM! Clean deprecation pattern.

The deprecation and delegation to the private helper follows the same pattern used in the MySQL module and aligns with the PR objective to make this option internal.


35-47: LGTM! Appropriate credential handling for root.

The private helper correctly removes credentials when using the root user, which is appropriate for Dolt's authentication model.


56-77: LGTM! Proper use of testcontainers.Run.

The refactoring correctly uses testcontainers.Run with assembled options, following the pattern established in the ClickHouse module. The order of appending options (module defaults → user opts → WithDefaultCredentials) ensures proper credential handling.


79-104: LGTM! Credential discovery correctly handles root case.

The post-start credential discovery properly inspects the container environment and correctly handles the root user case by clearing the password (line 102), which addresses the previous review comment. This ensures ConnectionString calls will emit root with an empty password.

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