From f85ff3a62ea81d17310d911754abe5b9306e3ef1 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 6 Dec 2021 13:18:44 -0800 Subject: [PATCH] Set clean state before testing `UseMU` in the MSI (#16543) --- .vsts-ci/windows/windows-packaging.yml | 1 + test/packaging/windows/msi.tests.ps1 | 39 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.vsts-ci/windows/windows-packaging.yml b/.vsts-ci/windows/windows-packaging.yml index b8aa2c2295..b413b7a639 100644 --- a/.vsts-ci/windows/windows-packaging.yml +++ b/.vsts-ci/windows/windows-packaging.yml @@ -51,6 +51,7 @@ pr: - src/Microsoft.WSMan.Runtime/Microsoft.WSMan.Runtime.csproj - src/Modules/PSGalleryModules.csproj - src/powershell-win-core/powershell-win-core.csproj + - test/packaging/windows/* - tools/ci.psm1 - tools/packaging/* diff --git a/test/packaging/windows/msi.tests.ps1 b/test/packaging/windows/msi.tests.ps1 index 9d1c218c4c..0ee34ca482 100644 --- a/test/packaging/windows/msi.tests.ps1 +++ b/test/packaging/windows/msi.tests.ps1 @@ -39,7 +39,7 @@ Describe -Name "Windows MSI" -Fixture { } function Get-UseMU { - $useMu = 0 + $useMu = $null $key = 'HKLM:\SOFTWARE\Microsoft\PowerShellCore\' if ($runtime -like '*x86*') { $key = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShellCore\' @@ -49,6 +49,25 @@ Describe -Name "Windows MSI" -Fixture { $useMu = Get-ItemPropertyValue -Path $key -Name UseMU -ErrorAction SilentlyContinue } catch {} + if (!$useMu) { + $useMu = 0 + } + + return $useMu + } + + function Set-UseMU { + param( + [int] + $Value + ) + $key = 'HKLM:\SOFTWARE\Microsoft\PowerShellCore\' + if ($runtime -like '*x86*') { + $key = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\PowerShellCore\' + } + + Set-ItemProperty -Path $key -Name UseMU -Value $Value -Type DWord + return $useMu } @@ -185,6 +204,15 @@ Describe -Name "Windows MSI" -Fixture { } Context "Add Path disabled" { + BeforeAll { + Set-UseMU -Value 0 + } + + It "UseMU should be 0 before install" -Skip:(!(Test-Elevated)) { + $useMu = Get-UseMU + $useMu | Should -Be 0 + } + It "MSI should install without error" -Skip:(!(Test-Elevated)) { { Invoke-MsiExec -Install -MsiPath $msiX64Path -Properties @{ADD_PATH = 0; USE_MU = 1; ENABLE_MU = 1} @@ -213,6 +241,15 @@ Describe -Name "Windows MSI" -Fixture { } Context "USE_MU disabled" { + BeforeAll { + Set-UseMU -Value 0 + } + + It "UseMU should be 0 before install" -Skip:(!(Test-Elevated)) { + $useMu = Get-UseMU + $useMu | Should -Be 0 + } + It "MSI should install without error" -Skip:(!(Test-Elevated)) { { Invoke-MsiExec -Install -MsiPath $msiX64Path -Properties @{USE_MU = 0}