test(hardware): add comprehensive unit tests for hardware manager#242
Closed
jra3 wants to merge 1 commit into
Closed
test(hardware): add comprehensive unit tests for hardware manager#242jra3 wants to merge 1 commit into
jra3 wants to merge 1 commit into
Conversation
…ecycle Add unit tests for hardware manager covering: - Constructor validation and defaults - Start/Stop lifecycle coordination - Context cancellation and graceful shutdown - Periodic update scheduling - Error handling for collector failures - Thread-safe concurrent access - Force update functionality - Hardware snapshot collection Test coverage: 64.9% on macOS (will be >80% on Linux where collectors fully function)
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
Adds comprehensive unit tests for the hardware manager (internal/hardware/manager.go) which previously had 0% test coverage.
Builds on top of PR #241 (CI bpftool fix).
Tests Added
Constructor & Configuration
TestNewManager_RequiresStore- Validates store requirementTestNewManager_AppliesDefaults- Verifies default interval (5min)TestNewManager_CustomInterval- Tests custom update intervalsTestManager_CollectionConfigDefaults- Validates ApplyDefaults() callLifecycle Management
TestManager_Lifecycle_StartAndStop- Basic start/stop flowTestManager_InitialDiscoveryNonFatal- Startup succeeds even when discovery failsTestManager_ContextCancellation- Graceful shutdown on context cancelTestManager_NeedLeaderElection- Validates runs on all nodesPeriodic Updates
TestManager_PeriodicUpdates- Validates timer-based updatesTestManager_GetLastUpdateTime- Tracks last update timeTestManager_ForceUpdate- Manual update triggeringCollector Integration
TestManager_CollectHardwareSnapshot_Success- Successful snapshot collectionTestManager_CollectHardwareSnapshot_WithInvalidPaths- Graceful failure handlingTestManager_CollectHardwareSnapshot_SnapshotFields- Snapshot field validationTestManager_UpdateHardwareGraph_ContextTimeout- Context timeout handlingThread Safety
TestManager_ConcurrentGetLastUpdateTime- Concurrent access validationCoverage
Per-function coverage on macOS:
Testing
go test ./internal/hardware -v -timeout 120sAll 15 tests pass successfully.
Closes #159
Related