test(hardware): add comprehensive error path tests for hardware graph#243
Closed
jra3 wants to merge 1 commit into
Closed
test(hardware): add comprehensive error path tests for hardware graph#243jra3 wants to merge 1 commit into
jra3 wants to merge 1 commit into
Conversation
Implement extensive error path testing for hardware graph components to increase test coverage from 70.9% to 80.4%, exceeding the >80% target for issue #160. The test suite covers three phases: Phase 1 - Critical error paths: - File access errors in getOSInfo (missing files, permission denied, malformed content) - System info error handling for uname failures - Resource store failures (system node creation, CPU packages, relationships) Phase 2 - Data validation: - Enum mapping edge cases (network interface modes, bus types, containment types) - Protobuf marshaling error scenarios - Bus type inference edge cases for PCI and network devices Phase 3 - Recovery testing: - Partial failure recovery in NUMA node creation - Duplicate relationship handling - Invalid resource reference handling - CPU package creation with missing cores Add MockStore implementation using testify/mock for controlled error injection during testing. Closes #160 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: John Allen <john@antimetal.com>
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
This PR adds comprehensive error path testing for hardware graph components to achieve >80% test coverage for previously under-tested error scenarios, addressing issue #160.
The implementation follows a three-phase testing approach covering critical error paths, data validation edge cases, and recovery scenarios.
What Changed
New Test File
internal/hardware/graph/error_paths_test.go(812 lines)Dependencies
github.com/stretchr/objx v0.5.2(required by testify/mock)Test Coverage by Phase
Phase 1: Critical Error Paths
getOSInfo): Missing files, permission denied, malformed content, empty files, quote handlinggetSystemInfo): Graceful error handling with fallback values for uname failuresPhase 2: Data Validation
Phase 3: Recovery Testing
Test Results
Coverage Improvement:
All tests passing:
Success Criteria Met
✅ Increase error path coverage to >80% for identified functions
✅ Test all identified failure scenarios from issue analysis
✅ Validate proper error messages and context propagation
✅ Ensure no panics on invalid input or edge cases
Testing Instructions
Implementation Details
MockStore Pattern
Uses testify/mock to create a controllable mock of the resource store interface, enabling:
Error Injection Strategy
Each test systematically exercises error paths:
Edge Case Coverage
Tests handle realistic failure scenarios:
Closes #160
Related