feat: Complete Test Coverage Improvements Feature#4
Merged
mattmattox merged 11 commits intomainfrom Nov 23, 2025
Merged
Conversation
Add extensive test coverage for cmd/node-doctor/main.go including: - Table-driven tests for createMonitors with various scenarios - NoopExporter tests (ExportStatus, ExportProblem, Stop, concurrent access) - MonitorFactoryAdapter tests for interface compliance - DumpConfiguration tests with output validation - Configuration loading tests with testdata fixtures - CreateExporters tests with lifecycle management New testdata fixtures: - valid_config.yaml: Basic valid configuration - invalid_syntax.yaml: Malformed YAML for error testing - empty_monitors.yaml: Edge case with empty monitor list - full_config.yaml: Complete configuration with all options Coverage improved from 20.7% to 22.0%. The theoretical maximum for this package is ~25-30% due to the untestable main() function which contains signal handling, os.Exit calls, and infinite loops. Ref: TaskForge #3836
Add comprehensive tests for previously uncovered functions: - TestIsReloadable: Verify interface implementation - TestReload: Test configuration reload with various scenarios - TestReloadNotStarted: Test reload on non-started exporter - TestNeedsServerRestart: Test server restart detection logic - TestNeedsMetricsRecreation: Test metrics recreation detection - TestLabelsEqual: Test label comparison edge cases - TestIsValidMetricName: Test metric name validation - TestValidateConfig: Test configuration validation - TestShutdownServer: Test server shutdown scenarios - TestExportProblemBeforeStart: Test error handling Add helper function waitForServerReady for robust server readiness checking instead of time.Sleep. Improve test reliability with t.Cleanup() for resource management and proper HTTP client timeouts. Coverage increased from 63.5% to 93.2%.
Add comprehensive tests for configuration validation and file watching: - Validator tests for all monitor types (kubelet, capacity, log-pattern, script, prometheus) with valid configs and error conditions - Security tests for script path validation (shell metacharacters) and file path validation (absolute path requirements) - Exporter validation tests (Kubernetes, Prometheus, HTTP) - Remediation and webhook configuration tests - Watcher tests for empty path handling and default debounce behavior - Tests for Kubernetes ConfigMap atomic update handling
- Fix integration tests by handling both ReloadCoordinator and detector event naming - Add webhook content comparison in exportersEqual (fixes config change detection bug) - Add comprehensive statistics tests for GetTotalExports, GetExportSuccessRate, GetDeduplicationRate - Add MonitorHandle tests for GetConfig, IsRunning, and Stop methods - Add ProblemDetector.Run() test coverage - Replace deprecated ioutil functions with os package equivalents - All tests pass with race detection enabled Task: #3829
Add comprehensive tests for previously uncovered functions: - IsReloadable, Reload, needsClientRecreation, annotationsEqual - performHealthCheck, logMetrics, StatsWithLastError - ReloadWithClientRecreation - ConditionUpdate.String - ConvertConditionsToNodeConditions with status mapping and type prefixing All tests use table-driven patterns and cover edge cases including nil inputs, empty collections, and error conditions.
Add comprehensive tests for HTTP exporter functionality including: - IsReloadable and Reload methods with various config scenarios - needsWorkerPoolRecreation logic for detecting config changes - performHealthCheck for webhook health monitoring - min helper function edge cases Create new stats_test.go with tests for all stats functions: - RecordDroppedRequest and RecordRetryAttempt tracking - GetTotalFailures, GetStatusSuccessRate, GetProblemSuccessRate - WebhookStatsSnapshot GetSuccessRate and IsHealthy methods - recordRequest with response time averaging - Thread-safe concurrent access validation TaskForge: #3831
Add comprehensive tests for network monitoring functions: - TestClassifyHTTPError_NetworkErrors: DNS, dial, and generic network errors - TestValidateURL: URL validation edge cases - TestIsValidHTTPMethod: HTTP method validation - TestGatewayMonitor_getGatewayIP: Gateway IP resolution - TestParseEndpointConfig_EdgeCases: Endpoint config type validation - TestNewConnectivityMonitor_EdgeCases: Monitor creation limits - TestValidateDNSConfig_EdgeCases: DNS config validation - TestCheckCustomQueries: Custom DNS query handling - TestParseConnectivityConfig_EdgeCases: Connectivity config parsing Coverage improvements: - classifyHTTPError: 57.9% → 89.5% - validateURL: 60% → 90% - isValidHTTPMethod: 75% → 100% - getGatewayIP: 40% → 80% - checkCustomQueries: 73.3% → 100% - parseConnectivityConfig: 82.6% → 100%
Add comprehensive tests for core types package: - Add ExporterReloadSummary tests (exporter_test.go): - TestExporterReloadSummary_AddResult with success/failure scenarios - TestExporterReloadResult_Fields for field validation - TestExporterReloadSummary_InitialState and order preservation tests - Add edge case validation tests (types_test.go): - TestProblemWithMetadata_NilMetadataMap for nil metadata handling - TestConditionValidation_EdgeCases for missing reason/message/transition - TestStatusValidation_EdgeCases for missing timestamp/invalid condition - TestProblemValidation_EdgeCases for missing severity/message/detected time - TestGetMetadata_NilMetadataMap for nil metadata retrieval Coverage: 78.1% -> 80.3% (exceeds 80% target) All tests pass with race detection.
Add comprehensive tests for nil logger handling and log methods across all remediator types: - base_test.go: Tests for logWarnf/logErrorf with nil and set logger - network_test.go: Tests for log methods and verifyRoutingTable direct calls - custom_test.go: Tests for GetScriptPath and log methods - disk_test.go: Tests for log methods with nil and set logger - registry_test.go: Tests for log methods with nil and set logger All tests use proper encapsulation via SetLogger() method calls.
…61.7% Add 9 new test functions for createExporters function: - TestCreateExporters_HTTPExporterEnabled - TestCreateExporters_PrometheusExporterEnabled - TestCreateExporters_HealthServerEnabled - TestCreateExporters_MultipleExportersEnabled - TestCreateExporters_HTTPExporterWithValidConfig - TestCreateExporters_PrometheusWithMetricsPath - TestCreateExporters_HTTPWithRetryConfig - TestCreateExporters_HealthServerWithCustomPaths - TestCreateExporters_ExporterCleanup Coverage target of 80%+ not achievable due to: - HTTP exporter success path requires valid kubeconfig/auth config - Kubernetes exporter requires actual kubeconfig - Would require integration tests or extensive mocking Task: #3856
- Add coverage-check target to Makefile with 80% threshold - Add coverage threshold check step to CI workflow for Go 1.25 - Create codecov.yml with project/patch coverage targets (80%) - Add input validation for missing coverage file and empty results - Keep Codecov as informational only (inline check is the hard gate) Task: #3835
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
Changes
CI Enhancements
make coverage-checkMakefile targetcodecov.ymlwith 80% project/patch coverage targetsTest plan
make build-node-doctor-local)make coverage-check- 81.8%)TaskForge Tasks: #3827, #3828, #3829, #3830, #3831, #3832, #3833, #3834, #3835, #3836