AksHci.Tests.ps1
ipmo .\Common.psm1 -force ipmo ..\TraceProvider\TraceProvider.psm1 -force ipmo ..\DownloadSdk\DownloadSdk.psm1 -force ipmo ..\Moc\Moc.psm1 -force ipmo ..\Kva\Kva.psm1 -force ipmo .\AksHci.psm1 -force Describe 'Test-KubernetesVersionUpdate' { It 'Should return false if current and target version are on different majors' { Test-KubernetesVersionUpdate -currentVersion "1.24.6" -targetVersion "2.24.7" | should -Be $false } It 'Should return false if current minor version is greater than target minor' { Test-KubernetesVersionUpdate -currentVersion "v1.25.7" -targetVersion "v1.24.9" | should -Be $false } It 'Should return false if current version is 2 or more minor versions behind targer' { Test-KubernetesVersionUpdate -currentVersion "1.23.12" -targetVersion "1.25.7" | should -Be $false } It 'Should return true if current version is one minor version behind target' { Test-KubernetesVersionUpdate -currentVersion "v1.23.12" -targetVersion "v1.24.9" | should -Be $true } It 'Should return true if current version on the same minor version as target' { Test-KubernetesVersionUpdate -currentVersion "1.23.12" -targetVersion "1.23.15" | should -Be $true } } Describe 'Get-MinSupportedMocVersion unit test' { It 'Should get min moc version' { InModuleScope AksHci { $AksHciVersion = "1.0.17.10310" $MinMocVersion = "1.0.13.2" $global:mocProductName = "mocstack" $MocProductRelease = [PSCustomObject]@{ ProductName = $global:mocProductName Version = $MinMocVersion } $AksHciProductStream = [PSCustomObject]@{ ProductReleases = @($MocProductRelease) } Mock -CommandName Get-ProductRelease -MockWith { return [PSCustomObject]@{ ProductStreamRefs = @($AksHciProductStream) Version = $AksHciVersion } } Mock -CommandName Get-MocVersion -MockWith { return "1.0.15.11104" } $productRelease = Get-ProductRelease -version $AksHciVersion -module "AksHci" $productRelease.Version | Should -Be $AksHciVersion $productRelease.ProductStreamRefs[0].ProductReleases[0].ProductName | Should -Be $global:mocProductName $productRelease.ProductStreamRefs[0].ProductReleases[0].Version | Should -Be $MinMocVersion (Get-MinSupportedMocVersion -aksHciVersion $AksHciVersion) | Should -Be $MinMocVersion } } It 'Min moc version should be null' { InModuleScope AksHci { $AksHciVersion = "1.0.17.10310" $MinMocVersion = $null $global:mocProductName = "mocstack" $MocProductRelease = [PSCustomObject]@{ ProductName = $global:mocProductName Version = $MinMocVersion } $AksHciProductStream = [PSCustomObject]@{ ProductReleases = @($MocProductRelease) } Mock -CommandName Get-ProductRelease -MockWith { return [PSCustomObject]@{ ProductStreamRefs = @($AksHciProductStream) Version = $AksHciVersion } } Mock -CommandName Get-MocVersion -MockWith { return "1.0.15.11104" } $productRelease = Get-ProductRelease -version $AksHciVersion -module "AksHci" $productRelease.Version | Should -Be $AksHciVersion $productRelease.ProductStreamRefs[0].ProductReleases[0].ProductName | Should -Be $global:mocProductName $productRelease.ProductStreamRefs[0].ProductReleases[0].Version | Should -Be $MinMocVersion (Get-MinSupportedMocVersion -aksHciVersion $AksHciVersion) | Should -Be $MinMocVersion } } } Describe 'Test-AksHciSupportedMocVersion unit test' { It 'Should succeed for compatible version of Moc' { InModuleScope AksHci { $AksHciVersion = "1.0.17.10310" Mock -CommandName Get-MocVersion -MockWith { return "1.0.15.11104" } Mock -CommandName Get-MinSupportedMocVersion -MockWith { return "1.0.13.2" } Mock -CommandName Get-InstallState -MockWith { return [InstallState]::Installed } Test-AksHciSupportedMocVersion -aksHciVersion $AksHciVersion | Should -Be $true } } It 'Should succeed if compatible version of Moc is not defined' { InModuleScope AksHci { $AksHciVersion = "1.0.17.10310" Mock -CommandName Get-MocVersion { return "1.0.15.11104" } Mock -CommandName Get-MinSupportedMocVersion -MockWith { return $null } Mock -CommandName Get-InstallState -MockWith { return [InstallState]::Installed } Test-AksHciSupportedMocVersion -aksHciVersion $AksHciVersion | Should -Be $true } } It 'Should fail if moc is incompatible with target AksHci version' { InModuleScope AksHci { $AksHciVersion = "1.0.17.10310" Mock -CommandName Get-MocVersion { return "1.0.15.11104" } Mock -CommandName Get-MinSupportedMocVersion -MockWith { return "1.0.17.10310" } Mock -CommandName Get-InstallState -MockWith { return [InstallState]::Installed } { Test-AksHciSupportedMocVersion -aksHciVersion $AksHciVersion } | Should -Throw } } It 'Should fail if moc is not installed' { InModuleScope AksHci { $AksHciVersion = "1.0.17.10310" Mock -CommandName Get-MocVersion { return "1.0.15.11104" } Mock -CommandName Get-MinSupportedMocVersion -MockWith { return "1.0.13.2" } Mock -CommandName Get-InstallState -MockWith { return [InstallState]::NotInstalled } { Test-AksHciSupportedMocVersion -aksHciVersion $AksHciVersion } | Should -Throw } } } |