(feat) start moving things to a factory to simplify to test #21
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.
This pull request refactors Consul client handling to use a new interface-based abstraction, improving testability and decoupling command logic from direct dependency on the HashiCorp Consul API. It introduces a factory pattern for Consul client creation, allowing easy mocking in tests, and updates both the
runandcleanupcommands and their tests to use this new approach. The changes also add comprehensive tests for various edge cases using the new mock infrastructure.Consul client abstraction and factory pattern:
ConsulClientandConsulAgentinterfaces, along with aClientFactoryabstraction inpkg/consul/factory.go, enabling dependency injection and easier mocking for tests. AddedDefaultFactoryfor real clients andMockFactoryfor test clients. ([pkg/consul/factory.goR1-R102](https://github.com/ncode/tagit/pull/21/files#diff-1142f61e0e32cf8339152cc77944982a9586034efa8d560f7b1bf950d664cdcfR1-R102))github.com/hashicorp/consul/apiincmd/cleanup.goandcmd/run.gowith the new factory-based approach, usingconsul.CreateClientfor client instantiation. ([[1]](https://github.com/ncode/tagit/pull/21/files#diff-1af21b9d6fc06756cac01f80ce66e7e10df29ff796851fb52e0870501b111868L23-R23),[[2]](https://github.com/ncode/tagit/pull/21/files#diff-8146f8148ccbf6711d65f532f6ab9a7c8dfbdc3960c7ffc974f17d6d224dd349L27-R27))cmd/cleanup.goandcmd/run.goto use the new interfaces and removed direct references to API-specific types, passing the abstracted client totagit.New. ([[1]](https://github.com/ncode/tagit/pull/21/files#diff-1af21b9d6fc06756cac01f80ce66e7e10df29ff796851fb52e0870501b111868L37-R50),[[2]](https://github.com/ncode/tagit/pull/21/files#diff-8146f8148ccbf6711d65f532f6ab9a7c8dfbdc3960c7ffc974f17d6d224dd349L62-R76),[[3]](https://github.com/ncode/tagit/pull/21/files#diff-8146f8148ccbf6711d65f532f6ab9a7c8dfbdc3960c7ffc974f17d6d224dd349L97-R96))Testing improvements:
cmd/cleanup_test.goandcmd/run_test.goto cover success, error, and edge scenarios for both commands. Tests now useconsul.SetFactoryto inject mock clients, verifying correct behavior without requiring a real Consul server. ([[1]](https://github.com/ncode/tagit/pull/21/files#diff-88bf4cf247b2469ebabdf721d68b5a01087e99ac1688ef053dc13b7f23dc7b7eR250-R279),[[2]](https://github.com/ncode/tagit/pull/21/files#diff-88bf4cf247b2469ebabdf721d68b5a01087e99ac1688ef053dc13b7f23dc7b7eR291-R501),[[3]](https://github.com/ncode/tagit/pull/21/files#diff-e5c6b0d9de21f1d8dee56a4b65988b10e5e74030b7dd52ef18195901e6f879adR489-R681))[[1]](https://github.com/ncode/tagit/pull/21/files#diff-88bf4cf247b2469ebabdf721d68b5a01087e99ac1688ef053dc13b7f23dc7b7eR5-R9),[[2]](https://github.com/ncode/tagit/pull/21/files#diff-e5c6b0d9de21f1d8dee56a4b65988b10e5e74030b7dd52ef18195901e6f879adR11-R12))