Skip to content

feat: IProviderFactory + command tests, 54%→62% coverage (+74 tests) - #65

Merged
cl8dep merged 2 commits into
mainfrom
feat/command-tests-and-coverage
Apr 29, 2026
Merged

feat: IProviderFactory + command tests, 54%→62% coverage (+74 tests)#65
cl8dep merged 2 commits into
mainfrom
feat/command-tests-and-coverage

Conversation

@cl8dep

@cl8dep cl8dep commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • IProviderFactory abstraction — extracts provider creation from static calls into an injectable interface, enabling command-level unit testing without network or credentials
  • 74 new tests covering PlanCommand, DriftCommand, ApplyCommand, CliIntegrationTests, and ConfigValidator
  • Coverage: 54.4% → 62.2% lines (57.9% branches, 80.2% methods)

Changes

Refactor

  • New IProviderFactory interface + DefaultProviderFactory wrapping the existing static ProviderFactory
  • All 5 commands (Plan, Apply, Drift, Diff, Import) now receive IProviderFactory via DI constructor injection
  • DefaultProviderFactory registered as singleton in Program.cs
  • Output validation (--output) moved inside try-catch in PlanCommand and DriftCommand — was throwing unhandled exceptions (returned -1 instead of 1)
  • DriftCommand now supports --zone flag (matching PlanCommand behavior)
  • Whitespace-only --zone values now explicitly rejected with error message

New test infrastructure

  • StubProvider — configurable IProvider stub with pre-loaded zones and apply results
  • StubProviderFactoryIProviderFactory stub with per-name provider routing
  • StubZoneResolver — moved to Helpers/, accepts pre-loaded zone dictionaries

New tests

File Tests Key coverage
CliIntegrationTests 32 Unknown commands, invalid flags, config errors, yaml→yaml end-to-end
PlanCommandTests 11 In-sync, diff, --exit-code, --output json, preflight failure
DriftCommandTests 10 In-sync, drift detection, --ignore-ttl, --output silent/json, --zone
ApplyCommandTests 11 In-sync, apply called, --max-changes, --force, preflight failure
ConfigValidatorTests 17 All provider types, missing credentials, zone errors, multi-error accumulation

Coverage delta

Class Before After
PlanCommand 0% 90%
DriftCommand 14% 93%
ApplyCommand 0% 42%
ConfigValidator 0% 100%
ConfigLoader 79% 99%

Test plan

  • dotnet test — 441 tests, 0 failures
  • No network calls — all tests run without credentials or external services

…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%
@cl8dep cl8dep added ci CI/CD and tooling feature New feature or capability labels Apr 29, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 77.27273% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/DnsSync/Commands/DiffCommand.cs 0.00% 3 Missing ⚠️
src/DnsSync/Commands/DriftCommand.cs 90.00% 1 Missing and 1 partial ⚠️
src/DnsSync/Commands/ImportCommand.cs 0.00% 2 Missing ⚠️
src/DnsSync/Commands/ApplyCommand.cs 75.00% 1 Missing ⚠️
src/DnsSync/Program.cs 0.00% 1 Missing ⚠️
src/DnsSync/Providers/DefaultProviderFactory.cs 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@cl8dep
cl8dep merged commit c785705 into main Apr 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci CI/CD and tooling feature New feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants