Skip to content

Improve test coverage for checker, vipconfig, and main packages#381

Draft
pashagolub wants to merge 6 commits into
masterfrom
pashagolub/studious-garbanzo
Draft

Improve test coverage for checker, vipconfig, and main packages#381
pashagolub wants to merge 6 commits into
masterfrom
pashagolub/studious-garbanzo

Conversation

@pashagolub
Copy link
Copy Markdown
Collaborator

@pashagolub pashagolub commented Jun 2, 2026

Motivation

Systematic test coverage improvement across critical packages to strengthen the test suite and establish patterns for reaching the 85% coverage target. Added comprehensive unit tests for edge cases, error paths, and CLI-level logic.

Changes

  • checker: Added timeout and error path tests for Patroni REST API scenarios
  • vipconfig: Added public API testing for NewConfig() constructor with os.Args manipulation
  • main: Added version flag handling tests and CLI output format validation
  • ipmanager: Added comprehensive tests for getMask (IPv4/IPv6 CIDR calculations), applyLoop (state management), and SyncStates (state synchronization) with mock configurer infrastructure

Coverage Results

  • Before: 46.4% overall
  • After: 52.0% overall (+5.6%)
  • Package breakdown: checker 88.7%, vipconfig 97.4%, ipmanager 18.7% (gaps identified for future work)

Technical Approach

  • Used mock configurer struct to test private functions (applyLoop, SyncStates)
  • Implemented table-driven tests for efficient multi-scenario testing (getMask IPv4/IPv6)
  • Applied cross-platform interface detection patterns for CI/CD compatibility

Remaining Work

Primary gap is ipmanager package (18.7% coverage). Future improvements should focus on:

  • Refactoring basicConfigurer into testable components
  • Creating comprehensive integration tests
  • Extracting testable main() orchestration logic
  • Expanding platform-specific testing infrastructure

Closes #380

pashagolub and others added 3 commits June 2, 2026 22:36
…, and vipconfig packages

- Add tests for getMask IPv4/IPv6 CIDR mask calculation
- Add tests for applyLoop and SyncStates with mock configurer
- Test IPv6 address support and different hosting types
- Add timeout test for Patroni checker
- Add NewConfig public API test with os.Args integration
- Improve error path coverage in ipmanager and vipconfig
- Current coverage: 51.0% (up from 46.4%)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add TestGetMask IPv4 out-of-range tests
- Add TestApplyLoop error scenarios (configure failure, query fails)
- Add TestApplyLoop_NoChangeNeeded test
- Add TestApplyLoop_DeconfigureWhenNeeded test
- Add TestGetNetIface_Success test with fallback logic
- Achieve 100% coverage for getMask, applyLoop, and SyncStates
- Overall coverage: 52.0% (up from 51.0%)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add TestVersionFlagHandling to test version flag detection logic
- Add TestVersionFlagOutput to verify version output format
- Test multiple arg combinations for version flag presence
- Provides foundation for testing CLI argument handling

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pashagolub pashagolub force-pushed the pashagolub/studious-garbanzo branch from a5baf04 to 66bb1e9 Compare June 2, 2026 20:54
@pashagolub pashagolub changed the title Improve test coverage to 52% with comprehensive unit tests Improve test coverage for checker, vipconfig, and main packages Jun 2, 2026
The test was expecting an error during Hetzner configurer creation,
but the function doesn't validate config at initialization time. The
error now correctly occurs from the loopback interface validation.
Added early return after error check to prevent calling err.Error()
on a nil error value, which caused a panic in GHA.
The test was using 'lo' (loopback), which exists and is up on CI systems.
Changed to a guaranteed non-existent interface name to ensure the test
always fails with 'failed to get interface' error as intended.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant