test(hardware): add comprehensive error path tests for hardware graph #243
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