Skip to content

refactor: replace Managed* wrappers with interfaces#655

Merged
aeneasr merged 3 commits intov4from
cleanup-api
Mar 17, 2026
Merged

refactor: replace Managed* wrappers with interfaces#655
aeneasr merged 3 commits intov4from
cleanup-api

Conversation

@aeneasr
Copy link
Copy Markdown
Member

@aeneasr aeneasr commented Mar 17, 2026

Summary

  • Replace ManagedResource, ManagedPool, ManagedNetwork wrapper structs with Go interfaces — removes ~115 lines of manual delegation boilerplate
  • *T variants return the restricted interface (Resource, Pool, Network); non-T variants return the closable interface (ClosableResource, ClosablePool, ClosableNetwork), providing the same compile-time safety with less code
  • Unexport Pool struct → pool, Network struct → dockerNetwork; public API is now entirely interface-based
  • ConnectToNetwork / DisconnectFromNetwork / GetIPInNetwork accept the Network interface directly — eliminates the ManagedNetwork.Network() escape hatch
  • Add NewResource(container.InspectResponse) ClosableResource constructor for external unit tests
  • Convert examples/cleanup/main.go to TestExplicitCleanup, demonstrating explicit lifecycle management without T helpers

Test plan

  • go build ./... — all files compile
  • go vet ./... — no vet issues
  • Unit tests (no Docker): go test -short ./...
  • Integration tests: go test ./...
  • Examples module: cd examples && go build ./...
  • Verify RunT returns Resource (no Close method visible)
  • Verify Run returns ClosableResource (has Close)
  • Verify NewPoolT returns Pool (no Close)
  • Verify NewPool returns ClosablePool (has Close)

🤖 Generated with Claude Code

Replace the concrete ManagedResource, ManagedPool, and ManagedNetwork
wrapper structs with Go interfaces. The *T variants now return the
restricted interface (Resource, Pool, Network) while the non-T variants
return the closable interface (ClosableResource, ClosablePool,
ClosableNetwork).

Key changes:
- Define Resource/ClosableResource, Network/ClosableNetwork,
  Pool/ClosablePool interfaces
- Unexport Pool struct → pool, Network struct → dockerNetwork
- Remove ~115 lines of manual delegation boilerplate
- ConnectToNetwork/DisconnectFromNetwork/GetIPInNetwork now accept the
  Network interface directly, removing the ManagedNetwork.Network()
  escape hatch
- Add NewResource constructor for external unit tests
- Convert examples/cleanup/main.go to TestExplicitCleanup test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aeneasr aeneasr changed the base branch from v3 to v4 March 17, 2026 13:49
aeneasr and others added 2 commits March 17, 2026 14:51
- var pool *dockertest.Pool → var pool dockertest.ClosablePool
  (pointer-to-interface is meaningless; NewPool returns ClosablePool)
- CloseT example: RunT returns Resource (no CloseT); use Run to get
  ClosableResource when explicit teardown is needed
- Registry function signatures: add return types (error, bool, slice)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aeneasr aeneasr merged commit fa8f486 into v4 Mar 17, 2026
6 checks passed
@aeneasr aeneasr deleted the cleanup-api branch March 17, 2026 14:11
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