Skip to content

Conversation

mdelapenya
Copy link
Member

  • chore: simpler host-port detection in tests
  • chore: ignore coverage files

What does this PR do?

It adds a simplification in the tests, something I missed to commit while reviewing #3254

I'm also ignoring the code coverage files, to avoid commiting them to git.

Why is it important?

Simpler code

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner September 18, 2025 09:29
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Sep 18, 2025
@mdelapenya mdelapenya self-assigned this Sep 18, 2025
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Sep 18, 2025
Copy link

coderabbitai bot commented Sep 18, 2025

Summary by CodeRabbit

  • Chores
    • Added coverage.out to .gitignore to prevent committing coverage artifacts.
  • Tests
    • Strengthened Atlas Local tests with more reliable connection parsing, resilient container checks, and stricter test credential file permissions to reduce flakiness.
  • Documentation
    • Clarified Option type docs to reference the Atlas Local container instead of an unrelated service.

Walkthrough

Adds coverage.out to .gitignore and updates MongoDB atlaslocal tests: use net.SplitHostPort for host:port parsing, switch Exec calls to multiplexed streams and non-fatal directory listings using an absolute path, and tighten auth file permissions from 0o755 to 0o600.

Changes

Cohort / File(s) Summary
Ignore rules update
\.gitignore
Adds a “# Coverage files” comment and ignores coverage.out immediately after .env.
MongoDB atlaslocal tests
modules/mongodb/atlaslocal/atlaslocal_test.go
- Parse host:port with net.SplitHostPort on the first host in connString.Hosts
- Switch Exec calls to use exec.Multiplexed() and read multiplexed output
- Use non-fatal `ls -1 /docker-entrypoint-initdb.d 2>/dev/null

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Test as atlaslocal_test.go
  participant Net as net.SplitHostPort
  participant Docker as container.Exec (Multiplexed)
  participant FS as Container FS

  rect rgba(200,230,255,0.25)
  note right of Test: Connection string parsing
  Test->>Net: SplitHostPort(connString.Hosts[0])
  Net-->>Test: host, port or error
  alt error
    Test->>Test: fail test
  else ok
    Test->>Test: assert host and port non-empty
  end
  end

  rect rgba(220,255,220,0.18)
  note right of Test: Init scripts check (non-fatal)
  Test->>Docker: Exec(multiplexed, "ls -1 /docker-entrypoint-initdb.d 2>/dev/null || true")
  Docker->>FS: list dir
  FS-->>Docker: stdout (possibly empty)
  Docker-->>Test: multiplexed output read and inspected
  end

  rect rgba(255,240,200,0.18)
  note right of Test: Auth files written with stricter perms
  Test->>FS: write username/password files with mode 0o600
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

In burrows of tests I twitch my nose,
I split host and port where the string now goes.
I ls with care, no panic, no shout—
Secrets snug with 0o600 about.
Git hides coverage.out, and I hop out. 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% 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 accurately and concisely reflects the primary change in this PR: simplifying host-port calculation in tests. It directly corresponds to the updates in modules/mongodb/atlaslocal/atlaslocal_test.go that replace brittle string parsing with net.SplitHostPort and related test adjustments. The conventional "chore(atlas):" prefix and short phrasing make the intent clear to reviewers.
Description Check ✅ Passed The PR description states the two reported changes—simpler host-port detection in tests and ignoring coverage files—which matches the modifications to atlaslocal_test.go and .gitignore in the provided summary. The description is on-topic and gives sufficient context for this small chore-level change even though it omits detailed testing steps. Therefore the description is related to the changeset and passes this lenient check.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 362ea4e and cabcd6f.

📒 Files selected for processing (2)
  • modules/mongodb/atlaslocal/atlaslocal_test.go (8 hunks)
  • modules/mongodb/atlaslocal/options.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • modules/mongodb/atlaslocal/options.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • modules/mongodb/atlaslocal/atlaslocal_test.go
⏰ 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). (15)
  • GitHub Check: lint (modules/pinecone) / lint: modules/pinecone
  • GitHub Check: lint (modules/vault) / lint: modules/vault
  • GitHub Check: lint (modules/nebulagraph) / lint: modules/nebulagraph
  • GitHub Check: lint (modules/cassandra) / lint: modules/cassandra
  • GitHub Check: lint (modules/surrealdb) / lint: modules/surrealdb
  • GitHub Check: lint (modules/mssql) / lint: modules/mssql
  • GitHub Check: lint (modules/etcd) / lint: modules/etcd
  • GitHub Check: lint (modules/solace) / lint: modules/solace
  • GitHub Check: lint (modules/influxdb) / lint: modules/influxdb
  • GitHub Check: lint (modules/dockermodelrunner) / lint: modules/dockermodelrunner
  • GitHub Check: lint (modules/dind) / lint: modules/dind
  • GitHub Check: lint (modules/memcached) / lint: modules/memcached
  • GitHub Check: lint (examples/nginx) / lint: examples/nginx
  • GitHub Check: lint (modules/socat) / lint: modules/socat
  • GitHub Check: Analyze (go)

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

Copy link

netlify bot commented Sep 18, 2025

Deploy Preview for testcontainers-go ready!

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

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 (3)
.gitignore (1)

24-25: Ignore coverage artifacts at any depth + common variants

Recommend broadening ignores so coverage files in submodules/tests aren’t accidentally committed.

 # Coverage files
-coverage.out
+coverage.out
+**/coverage.out
+cover.out
+*.coverprofile
modules/mongodb/atlaslocal/atlaslocal_test.go (2)

7-7: Guard against empty Hosts slice before SplitHostPort

Minor robustness: assert hosts present before indexing.

 			require.Equal(t, "mongodb", connString.Scheme)
+			require.NotEmpty(t, connString.Hosts, "connection string must have at least one host")
 			host, port, err := net.SplitHostPort(connString.Hosts[0])
 			require.NoError(t, err, "Invalid host:port")
 			require.NotEmpty(t, host)
 			require.NotEmpty(t, port)

Also applies to: 545-549


766-772: Demux Exec stream before matching; Docker multiplex header can skew output

ctr.Exec returns a multiplexed stream; without stripping the 8‑byte header you can get false positives/negatives when checking for filenames. Align with requireEnvVar’s handling.

-		cmd := []string{"sh", "-lc", "ls -1 /docker-entrypoint-initdb.d 2>/dev/null || true"}
-		_, reader, err := ctr.Exec(context.Background(), cmd)
+		cmd := []string{"sh", "-lc", "ls -1 /docker-entrypoint-initdb.d 2>/dev/null || true"}
+		_, reader, err := ctr.Exec(context.Background(), cmd)
 		require.NoError(t, err)
 
-		content, _ := io.ReadAll(reader)
-		require.NotContains(t, string(content), filename)
+		raw, err := io.ReadAll(reader)
+		require.NoError(t, err)
+		out := raw
+		if len(raw) >= 8 {
+			out = raw[8:]
+		}
+		require.NotContains(t, string(out), filename)

Optional: apply similar demuxing in requireInitScriptsExist for consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e14bda and 362ea4e.

📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • modules/mongodb/atlaslocal/atlaslocal_test.go (5 hunks)
⏰ 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). (18)
  • GitHub Check: lint (modules/vearch) / lint: modules/vearch
  • GitHub Check: lint (modules/mockserver) / lint: modules/mockserver
  • GitHub Check: lint (modules/dockermcpgateway) / lint: modules/dockermcpgateway
  • GitHub Check: lint (modules/ollama) / lint: modules/ollama
  • GitHub Check: lint (modules/couchbase) / lint: modules/couchbase
  • GitHub Check: lint (modules/toxiproxy) / lint: modules/toxiproxy
  • GitHub Check: lint (modules/arangodb) / lint: modules/arangodb
  • GitHub Check: lint (modules/k3s) / lint: modules/k3s
  • GitHub Check: lint (modules/etcd) / lint: modules/etcd
  • GitHub Check: lint (modules/nats) / lint: modules/nats
  • GitHub Check: lint (modules/dynamodb) / lint: modules/dynamodb
  • GitHub Check: lint (modules/postgres) / lint: modules/postgres
  • GitHub Check: lint (modules/inbucket) / lint: modules/inbucket
  • GitHub Check: lint (modules/pulsar) / lint: modules/pulsar
  • GitHub Check: lint (modules/compose) / lint: modules/compose
  • GitHub Check: lint (modules/mariadb) / lint: modules/mariadb
  • GitHub Check: lint (modules/meilisearch) / lint: modules/meilisearch
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
modules/mongodb/atlaslocal/atlaslocal_test.go (1)

797-807: Good hardening: credentials 0600

Tightening username/password file perms to 0600 is correct for secrets.

@mdelapenya mdelapenya merged commit 404b345 into testcontainers:main Sep 18, 2025
213 checks passed
@mdelapenya mdelapenya deleted the atlas-refinement branch September 18, 2025 12:08
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