Private/core-driverpack/Get-OSDCloudDriverPackCompatibilityCatalog.Tests.ps1

BeforeAll {
    . $PSScriptRoot\ConvertTo-OSDCloudDriverPack.ps1
    . $PSScriptRoot\Get-OSDCloudDriverPackCompatibilityCatalog.ps1

    function Get-OSDCoreDriverPackCatalogDell {
        [CmdletBinding()]
        param ([switch]$LocalOnly, [string]$LocalDriverPackCatalog)
    }

    function Get-OSDCoreDriverPackCatalogHP {
        [CmdletBinding()]
        param ([switch]$LocalOnly, [string]$LocalDriverPackCatalog)
    }

    function Get-OSDCoreDriverPackCatalogLenovo {
        [CmdletBinding()]
        param ([switch]$LocalOnly, [string]$LocalDriverPackCatalog)
    }

    function Get-OSDCoreDriverPackCatalogPanasonic {
        [CmdletBinding()]
        param ([switch]$LocalOnly, [string]$LocalDriverPackCatalog)
    }

    function Get-OSDCoreDriverPackCatalogSurface {
        [CmdletBinding()]
        param ([switch]$LocalOnly, [string]$LocalDriverPackCatalog)
    }

    $script:testCoreDriverPack = [PSCustomObject]@{
        CatalogVersion  = '26.09.30'
        ReleaseDate     = '26.09.30'
        Name            = 'Test Driver Pack [26.09.30]'
        Manufacturer    = 'Test'
        Model           = 'Test Model'
        SystemId        = 'TEST-01'
        FileName        = 'test.cab'
        Url             = 'https://example.test/test.cab'
        OperatingSystem = 'Windows 11'
        OSArchitecture  = 'amd64'
        OSVersion       = '26H2'
        HashMD5         = '0123456789ABCDEF0123456789ABCDEF'
    }
    $script:testGenericDriverPackJson = @'
{
    "CatalogVersion": "26.09.30",
    "ReleaseDate": "26.09.29",
    "Name": "Generic Driver Pack [26.09.29]",
    "Manufacturer": "Generic",
    "Model": "Generic Model",
    "SystemId": "GENERIC-01",
    "FileName": "generic.cab",
    "Url": "https://example.test/generic.cab",
    "OperatingSystem": "Windows 11",
    "OSArchitecture": "arm64",
    "OSVersion": "26H2",
    "HashMD5": "FEDCBA9876543210FEDCBA9876543210"
}
'@

}

Describe 'Get-OSDCloudDriverPackCompatibilityCatalog' {
    BeforeEach {
        Mock Test-Path { $true }
        Mock Get-OSDCoreDriverPackCatalogDell { $script:testCoreDriverPack }
        Mock Get-OSDCoreDriverPackCatalogHP { @() }
        Mock Get-OSDCoreDriverPackCatalogLenovo { @() }
        Mock Get-OSDCoreDriverPackCatalogPanasonic { @() }
        Mock Get-OSDCoreDriverPackCatalogSurface { @() }
        Mock Get-Content { $script:testGenericDriverPackJson }
    }

    It 'reads local core catalogs and returns compatibility objects' {
        $result = @(Get-OSDCloudDriverPackCompatibilityCatalog -ModuleBase 'C:\OSD')

        $result | Should -HaveCount 2
        $result.Product | Should -Contain 'TEST-01'
        $result.Product | Should -Contain 'GENERIC-01'
        Should -Invoke Get-OSDCoreDriverPackCatalogDell -Exactly 1 -ParameterFilter { $LocalOnly }
        Should -Invoke Get-OSDCoreDriverPackCatalogSurface -Exactly 1 -ParameterFilter { $LocalOnly }
    }

    It 'throws when a required core catalog is missing' {
        Mock Test-Path { $false }

        { Get-OSDCloudDriverPackCompatibilityCatalog -ModuleBase 'C:\OSD' } |
            Should -Throw '*Required driver pack catalog was not found*'
    }
}