feat: IProviderFactory + command tests, 54%→62% coverage (+74 tests) - #65
Merged
Conversation
…54%→62% coverage ## Refactor - Extract IProviderFactory interface + DefaultProviderFactory wrapping the static ProviderFactory - Inject IProviderFactory into all 5 commands (Plan, Apply, Drift, Diff, Import) replacing direct static calls - Register DefaultProviderFactory as singleton in Program.cs DI container - Move output validation inside try-catch in PlanCommand and DriftCommand (was throwing unhandled) - Add --zone flag to DriftCommand (matching PlanCommand behavior) - Reject whitespace-only --zone values in PlanCommand with explicit error ## Tests (+74) - StubProvider + StubProviderFactory helpers for command-level testing without network - StubZoneResolver moved to Helpers/ and supports pre-loaded zone dictionaries - PlanCommandTests (11): in-sync, diff, --exit-code, --output json, preflight failure - DriftCommandTests (10): in-sync, drift detection, --ignore-ttl, --output silent/json, preflight failure - ApplyCommandTests (11): in-sync, apply called, --max-changes guard, --force, preflight failure - ConfigValidatorTests (17): all provider types, missing credentials, zone errors, multi-error accumulation - CliIntegrationTests (32): unknown commands, invalid flags, config errors, valid yaml→yaml end-to-end ## Coverage 54.4% → 62.2% lines | 50.2% → 57.9% branches | 73.5% → 80.2% methods PlanCommand: 0% → 90% | DriftCommand: 14% → 93% | ConfigValidator: 0% → 100%
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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
IProviderFactoryabstraction — extracts provider creation from static calls into an injectable interface, enabling command-level unit testing without network or credentialsPlanCommand,DriftCommand,ApplyCommand,CliIntegrationTests, andConfigValidatorChanges
Refactor
IProviderFactoryinterface +DefaultProviderFactorywrapping the existing staticProviderFactoryPlan,Apply,Drift,Diff,Import) now receiveIProviderFactoryvia DI constructor injectionDefaultProviderFactoryregistered as singleton inProgram.cs--output) moved insidetry-catchinPlanCommandandDriftCommand— was throwing unhandled exceptions (returned-1instead of1)DriftCommandnow supports--zoneflag (matchingPlanCommandbehavior)--zonevalues now explicitly rejected with error messageNew test infrastructure
StubProvider— configurableIProviderstub with pre-loaded zones and apply resultsStubProviderFactory—IProviderFactorystub with per-name provider routingStubZoneResolver— moved toHelpers/, accepts pre-loaded zone dictionariesNew tests
CliIntegrationTestsPlanCommandTests--exit-code,--output json, preflight failureDriftCommandTests--ignore-ttl,--output silent/json,--zoneApplyCommandTests--max-changes,--force, preflight failureConfigValidatorTestsCoverage delta
PlanCommandDriftCommandApplyCommandConfigValidatorConfigLoaderTest plan
dotnet test— 441 tests, 0 failures