Skip to content

chore(wait): apply review suggestions to exit_test and health_test (follow-up to #3603)#3724

Closed
mdelapenya wants to merge 1 commit into
testcontainers:mainfrom
mdelapenya:fix/pr-3603-review-suggestions-v2
Closed

chore(wait): apply review suggestions to exit_test and health_test (follow-up to #3603)#3724
mdelapenya wants to merge 1 commit into
testcontainers:mainfrom
mdelapenya:fix/pr-3603-review-suggestions-v2

Conversation

@mdelapenya

Copy link
Copy Markdown
Member

This is a follow-up to #3603, demonstrating the review feedback applied and passing tests.

Changes vs #3603

  • wait/exit_test.go and wait/health_test.go migrated from package wait to package wait_test
  • Hand-written mock structs removed; replaced with mockStrategyTarget (already generated, already checked in)
  • Typed EXPECT() chains used throughout (.EXPECT().State(anyContext).Return(...)) — consistent with file_test.go and log_test.go
  • anyContext matcher reused for context arguments
  • Import paths updated to github.com/moby/moby/api/types/container
  • Typed container.State* constants used instead of raw string literals
  • newStateTarget(t, state) helper extracted in health_test.go, mirroring newRunningTarget pattern
  • TestWaitForHealthWithNil: goroutine+mutex pattern replaced with a RunAndReturn time-based closure — no goroutines, same semantics, cleaner

Test results

--- PASS: TestWaitForExit (0.00s)
--- PASS: TestWaitForHealthTimesOutForUnhealthy (0.20s)
--- PASS: TestWaitForHealthSucceeds (0.00s)
--- PASS: TestWaitForHealthWithNil (0.20s)
--- PASS: TestWaitForHealthFailsDueToOOMKilledContainer (0.00s)
--- PASS: TestWaitForHealthFailsDueToExitedContainer (0.00s)
--- PASS: TestWaitForHealthFailsDueToUnexpectedContainerStatus (0.00s)
ok  github.com/testcontainers/testcontainers-go/wait  0.413s

go build ./wait/... and go vet ./wait/... are clean.

Part of #2765.

- Switch to package wait_test
- Replace hand-written mocks with mockStrategyTarget + typed EXPECT() chains
- Use anyContext matcher for context args
- Use moby/moby import paths (not docker/docker)
- Use typed container state constants
- Extract newStateTarget() helper in health_test.go
- Replace goroutine+mutex pattern in TestWaitForHealthWithNil with RunAndReturn closure

Addresses review feedback on PR testcontainers#3603.
@mdelapenya mdelapenya requested a review from a team as a code owner June 13, 2026 07:49
@netlify

netlify Bot commented Jun 13, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 39010f0
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6a2d0b9164020400085ccdc3
😎 Deploy Preview https://deploy-preview-3724--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

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3569bff7-e6c8-4310-b248-ba400932d155

📥 Commits

Reviewing files that changed from the base of the PR and between 465d002 and 39010f0.

📒 Files selected for processing (2)
  • wait/exit_test.go
  • wait/health_test.go

Summary by CodeRabbit

  • Tests
    • Refactored test organization to use external package testing approach and standardized mock strategies for improved test maintainability.

Walkthrough

Tests for the wait package exit and health strategies are refactored to use external package testing (wait_test) with shared mock helpers. The exit test and all health tests remove hand-written mock types and use mock strategy targets instead, while constructor calls are updated to use the exported package names.

Changes

Wait Strategy Test External Package Refactoring

Layer / File(s) Summary
Exit strategy test external package conversion
wait/exit_test.go
Exit test migrated to external wait_test package; hand-written exitStrategyTarget mock removed in favor of newMockStrategyTarget(t) that mocks the State method, and constructor call updated to wait.NewExitStrategy().
Health strategy test external package conversion and mock refactoring
wait/health_test.go
Health tests migrated to external wait_test package; healthStrategyTarget mock removed and replaced with newStateTarget helper that returns a mocked target with configurable State return value. All test cases (TestWaitForHealthSucceeds, TestWaitForHealthWithNil, TestWaitFailsForNilHealth, and container status failure tests) updated to use the new mock helpers and wait.NewHealthStrategy() constructor.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Tests hop into the light of day,
From private walls to public way,
Mock helpers shared, no more duplication—
Clean refactoring, celebration!
External eyes now watch them play.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: applying review suggestions to exit_test and health_test as a follow-up to #3603.
Description check ✅ Passed The description is directly related to the changeset, providing clear details about the migration from package wait to wait_test and the refactoring of mock structures.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown
Member Author

Closing — reopening correctly targeted against the author's fork branch feat/issue-2765-generated-mocks-wait.

@mdelapenya mdelapenya closed this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant