refactor: replace Managed* wrappers with interfaces#655
Merged
Conversation
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>
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ManagedResource,ManagedPool,ManagedNetworkwrapper structs with Go interfaces — removes ~115 lines of manual delegation boilerplate*Tvariants 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 codePoolstruct →pool,Networkstruct →dockerNetwork; public API is now entirely interface-basedConnectToNetwork/DisconnectFromNetwork/GetIPInNetworkaccept theNetworkinterface directly — eliminates theManagedNetwork.Network()escape hatchNewResource(container.InspectResponse) ClosableResourceconstructor for external unit testsexamples/cleanup/main.gotoTestExplicitCleanup, demonstrating explicit lifecycle management without T helpersTest plan
go build ./...— all files compilego vet ./...— no vet issuesgo test -short ./...go test ./...cd examples && go build ./...RunTreturnsResource(noClosemethod visible)RunreturnsClosableResource(hasClose)NewPoolTreturnsPool(noClose)NewPoolreturnsClosablePool(hasClose)🤖 Generated with Claude Code