-
-
Notifications
You must be signed in to change notification settings - Fork 581
chore(atlas): simplify host-port calculation in tests #3300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary by CodeRabbit
WalkthroughAdds Changes
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
Comment |
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this 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 variantsRecommend broadening ignores so coverage files in submodules/tests aren’t accidentally committed.
# Coverage files -coverage.out +coverage.out +**/coverage.out +cover.out +*.coverprofilemodules/mongodb/atlaslocal/atlaslocal_test.go (2)
7-7
: Guard against empty Hosts slice before SplitHostPortMinor 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 outputctr.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
📒 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 0600Tightening username/password file perms to 0600 is correct for secrets.
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