Skip to content

test: Add comprehensive unit tests for hardware manager lifecycle #159

@jra3

Description

@jra3

Summary

The hardware manager (internal/hardware/manager.go) currently has 0% test coverage despite being a critical 297-line component responsible for hardware discovery lifecycle management.

Background

The hardware manager coordinates:

  • Periodic hardware discovery scheduling
  • Performance collector integration
  • Graceful startup/shutdown lifecycle
  • Error handling and recovery
  • Resource cleanup

Missing Test Coverage

Critical Functions (0% coverage):

  • NewManager - Constructor validation
  • Start - Startup sequence and initial discovery
  • Stop - Graceful shutdown coordination
  • runPeriodicUpdates - Periodic scheduling logic
  • updateHardwareGraph - Core update orchestration
  • collectHardwareSnapshot - Performance collector integration

Test Implementation Plan

1. Lifecycle Tests

func TestManager_Lifecycle(t *testing.T) {
    // Test successful Start/Stop coordination
    // Test context cancellation propagation
    // Test WaitGroup synchronization
}

2. Error Handling Tests

func TestManager_StartupErrors(t *testing.T) {
    // Test initial discovery failures (non-fatal)
    // Test performance manager integration errors
    // Test resource store failures
}

3. Periodic Update Tests

func TestManager_PeriodicUpdates(t *testing.T) {
    // Test timer-based updates
    // Test update failure recovery
    // Test shutdown during update
}

4. Collector Integration Tests

func TestManager_CollectorIntegration(t *testing.T) {
    // Test partial collector failures
    // Test collector timeout handling
    // Test snapshot assembly
}

Success Criteria

  • Achieve >80% test coverage for manager.go
  • Test all public methods and critical private methods
  • Cover error paths and edge cases
  • Validate proper resource cleanup
  • Test concurrent access patterns

Priority

HIGH - This component manages the entire hardware discovery subsystem and lacks any test coverage.

Related

Part of hardware discovery feature testing improvements following initial implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions