test(config): add comprehensive tests for config loading path #81
Reference in New Issue
Block a user
Delete Branch "fix/72-config-test-coverage"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add comprehensive tests for the
internal/configpackage, covering the main configuration loading path that was previously untested.Closes issue #72
What Changed
Added three new test files:
config_test.go— 16 tests coveringNew(),StatePath(), and the full config loading pipelineparsecsv_test.go— 10 test cases forparseCSV()edge casesexport_test.go— standard Go export bridge for testing unexportedparseCSVTest Coverage
PORT(unprefixed)DNSWATCHER_DNS_INTERVAL=bananafalls back to 1hDNSWATCHER_TLS_INTERVAL=notadurationfalls back to 12hDNSWATCHER_TARGETSreturnsErrNoTargetsco.uk) rejected with errorDNSWATCHER_DEBUG=trueenables debug loggingDataDirvaluesCoverage: 23% → 92.5%
Notes
viper.Reset()for isolation since Viper has global statet.Setenv()for automatic env var cleanupassert/requireconsistent with other test files in the repo✅ Review: PASS
Summary
25+ new tests for
internal/configcovering config loading, environment overrides, edge cases, and theparseCSVhelper. Coverage goes from 23% to ~92.5%. Clean, well-structured test code.Checklist
config_test.go,export_test.go, andparsecsv_test.goadded. Zero production files modified..golangci.ymlunchanged.docker build .succeeds (all checks pass includingmake check).Test Coverage Highlights
DNSWATCHER_TARGETSis setErrNoTargets), empty CSV segments, public suffix rejectionDNSWATCHER_DNS_INTERVALandDNSWATCHER_TLS_INTERVALfall back to defaultsparseCSVedge cases: Empty string, whitespace, trailing/leading commas, consecutive commas, tabs — 10 test casesStatePath: Multiple data directory variants verifiedPORTenv var works (notDNSWATCHER_PORT)Notes
t.Parallel()due to viper global state — documented with a comment. Each test resets viper for isolation.export_test.goexportsparseCSVfor external package testing — correct Go pattern.t.Setenv()for env var isolation (automatically restored after each test).testify/assertandtestify/requireconsistently, matching the project's existing test style.Ready to merge.
✅ Review: PASS
Summary
Excellent test coverage for the
internal/configpackage. Takes coverage from 23% to 92.5% with clean, well-structured tests that exercise the full config loading pipeline.What Was Reviewed
config_test.go(260 lines) — 16 tests coveringNew(),StatePath(), and the full config pipelineparsecsv_test.go(44 lines) — 10 test cases forparseCSV()edge casesexport_test.go(6 lines) — standard Go export bridge forparseCSVChecklist
PORTbanana→ 1h,notaduration→ 12h, both invalid simultaneouslyErrNoTargetsco.uk) correctly rejecteddnswatcherconfig file nameclassify_test.gountoucheddocker build .passes (no-cache, all tests green, lint clean)viper.Reset()before each test,t.Setenv()for env cleanuptestify/assert+testify/require, matches existing test patternsTestStatePathandTestParseCSVuset.Parallel(), Viper-dependent tests correctly sequentialNotes
export_test.gobridge pattern rather than makingparseCSVpublicNo issues found. Ready to merge.