diff --git a/.github/workflows/scripts.yml b/.github/workflows/scripts.yml index 46b93a5..13946bd 100644 --- a/.github/workflows/scripts.yml +++ b/.github/workflows/scripts.yml @@ -21,6 +21,10 @@ jobs: - name: Parse + analyze PowerShell shell: pwsh run: | + # Register the gallery if the runner image has not, then trust it. Set-PSRepository fails hard when + # PSGallery is not registered yet - an intermittent runner-image state that has flaked this job - + # so register-if-missing rather than assume it is there. + if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) { Register-PSRepository -Default } Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module PSScriptAnalyzer -Force -Scope CurrentUser $dirs = 'appliance', 'installer/windows' @@ -51,6 +55,7 @@ jobs: - name: Pester (Hyper-V import logic, cmdlets mocked) shell: pwsh run: | + if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) { Register-PSRepository -Default } Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module Pester -MinimumVersion 5.5.0 -Force -Scope CurrentUser -SkipPublisherCheck Import-Module Pester diff --git a/appliance/Import-DispatchAppliance.Tests.ps1 b/appliance/Import-DispatchAppliance.Tests.ps1 index 09fad4d..1adddf4 100644 --- a/appliance/Import-DispatchAppliance.Tests.ps1 +++ b/appliance/Import-DispatchAppliance.Tests.ps1 @@ -33,7 +33,12 @@ Describe 'Import-DispatchAppliance (unattended)' { Mock Set-VMMemory {} Mock Set-VMNetworkAdapterVlan {} Mock Start-VM {} - Mock Copy-Item {} + # Create the destination, rather than mocking the copy away to nothing. The script verifies the + # copy landed (Test-Path -PathType Leaf) before handing the path to New-VM - a real guard, since a + # silently failed copy would otherwise produce a VM pointed at a missing disk. A no-op mock made + # that guard throw on every test that got as far as the copy, which is why four of the six here have + # failed since they were written. + Mock Copy-Item { New-Item -ItemType File -Path $Destination -Force | Out-Null } } It 'keeps VM config + disk together under \' {