Tests/SysInfoToolkit.Tests.ps1

BeforeAll {
    $ModulePath = Join-Path $PSScriptRoot '..'
    Remove-Module SysInfoToolkit -ErrorAction SilentlyContinue
    Import-Module $ModulePath -Force
}

Describe 'SysInfoToolkit module structure' {

    It 'Exports exactly the three intended public functions' {
        $exported = (Get-Command -Module SysInfoToolkit).Name
        $exported | Should -Contain 'Get-DiskSpace'
        $exported | Should -Contain 'Get-MemoryUsage'
        $exported | Should -Contain 'Get-SystemUptime'
        $exported.Count | Should -Be 3
    }

    It 'Does not export the private helper function' {
        (Get-Command -Module SysInfoToolkit).Name | Should -Not -Contain 'ConvertTo-FriendlySize'
    }
}

Describe 'Get-DiskSpace' {

    It 'Returns objects with the expected properties' {
        $result = Get-DiskSpace | Select-Object -First 1
        $result.PSObject.Properties.Name | Should -Contain 'DriveLetter'
        $result.PSObject.Properties.Name | Should -Contain 'TotalSizeGB'
        $result.PSObject.Properties.Name | Should -Contain 'FreeSpaceGB'
        $result.PSObject.Properties.Name | Should -Contain 'PercentFree'
    }

    It 'Filters by MinFreePercent when specified' {
        # Every volume has 100% or less free, so this should return everything -
        # mainly proves the parameter doesn't throw and behaves as a real filter.
        $all = Get-DiskSpace -MinFreePercent 100
        $strict = Get-DiskSpace -MinFreePercent 0
        $strict.Count | Should -BeLessOrEqual $all.Count
    }
}

Describe 'Get-MemoryUsage' {

    It 'Returns a single object with friendly size strings' {
        $result = Get-MemoryUsage
        $result.TotalMemory | Should -Match '\d+(\.\d+)? (GB|MB)'
        $result.PercentUsed | Should -BeOfType [double]
    }
}