Fix MSI Tests

This commit is contained in:
Twangboy 2022-12-23 14:04:26 -07:00
parent 76731ff26f
commit 13bd49ac5d
No known key found for this signature in database
GPG key ID: ED267D5C0DE6F8A6
42 changed files with 271 additions and 112 deletions

View file

@ -1,5 +1,3 @@
@echo off
del *.wixobj
del CustomAction01\*.pdb
del CustomAction01\*.dll
del Product-discovered-files-*.wxs
@ echo off
Set "CurDir=%~dp0"
PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\clean.ps1" %*

57
pkg/windows/msi/clean.ps1 Normal file
View file

@ -0,0 +1,57 @@
# Clean up the test environment
#-------------------------------------------------------------------------------
# Script Variables
#-------------------------------------------------------------------------------
$PROJECT_DIR = $(git rev-parse --show-toplevel)
$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName
$BUILD_DIR = "$PROJECT_DIR\pkg\windows\build"
$BUILDENV_DIR = "$PROJECT_DIR\pkg\windows\buildenv"
$TESTS_DIR = "$SCRIPT_DIR\config_tests"
#-------------------------------------------------------------------------------
# Script Functions
#-------------------------------------------------------------------------------
function Write-Result($result, $ForegroundColor="Green") {
$position = 80 - $result.Length - [System.Console]::CursorLeft
Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "")
}
#-------------------------------------------------------------------------------
# Script Begin
#-------------------------------------------------------------------------------
Write-Host $("=" * 80)
Write-Host "Clean the Test Environment" -ForegroundColor Cyan
Write-Host $("-" * 80)
#-------------------------------------------------------------------------------
# Delete Files
#-------------------------------------------------------------------------------
$delete_files = "*.wixobj",
"CustomAction01\*.pdb",
"CustomAction01\*.dll",
"*Product-discovered-files-*.wxs"
$delete_files | ForEach-Object {
if ( Test-Path -Path "$_" ) {
Write-Host "Deleting $_`: " -NoNewline
Remove-Item -Path "$_" -Force -Recurse -ErrorAction SilentlyContinue
if (!(Test-Path -Path "$_")) {
Write-Result "Success"
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
}
}
#-------------------------------------------------------------------------------
# Script Complete
#-------------------------------------------------------------------------------
Write-Host $("-" * 80)
Write-Host "Clean the Test Environment Complete" -ForegroundColor Cyan
Write-Host $("=" * 80)

View file

@ -1 +0,0 @@
msiexec /i %* /l*v %1-install.log

View file

@ -1,4 +0,0 @@
@ echo off
pushd tests\config_tests
call clean
popd

View file

@ -1,3 +0,0 @@
rem If you want to test config-tests, do this before building
xcopy /s /y _mock_salt_pkg_windows\buildenv ..\salt\pkg\windows\buildenv\
xcopy /s /y _mock_salt_pkg_windows\build ..\salt\pkg\windows\build\

View file

@ -1,3 +0,0 @@
pushd tests\config_tests
PowerShell -ExecutionPolicy RemoteSigned -File test.ps1
popd

View file

@ -1,22 +0,0 @@
@echo off
IF exist "c:\salt\conf" (
echo "c:\salt"
dir /b "c:\salt"
echo "c:\salt\conf"
dir /b /s "c:\salt\conf" )
IF exist "C:\ProgramData\Salt Project\salt\conf" (
echo "C:\ProgramData\Salt Project\salt\conf"
dir /b "C:\ProgramData\Salt Project\salt\conf" )
IF exist "C:\Program Files (x86)\Salt Project\salt" (
echo "C:\Program Files (x86)\Salt Project\salt"
dir /b "C:\Program Files (x86)\Salt Project\salt" )
IF exist "C:\Program Files\Salt Project\salt" (
echo "C:\Program Files\Salt Project\salt"
dir /b "C:\Program Files\Salt Project\salt" )
Reg Query "HKLM\SOFTWARE\Salt Project\salt"
sc query salt-minion

View file

@ -4,7 +4,7 @@
### Edit a `*.test` file
- Contains the msi-properties, of which master and minion_id simulate user input via the GUI
- May contain the `dormant` keyword, which means the configuration remains (dormant) after uninstall
- Without the `dormant` keyword, no configuaration must exist after uninstall
- Without the `dormant` keyword, no configuration must exist after uninstall
### Optionally edit a `*.minion_id` file
- Contains prior configuration by conf/minion_id file

View file

@ -0,0 +1,3 @@
@ echo off
Set "CurDir=%~dp0"
PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\clean.ps1"

View file

@ -0,0 +1,77 @@
# Clean up the test environment
#-------------------------------------------------------------------------------
# Script Variables
#-------------------------------------------------------------------------------
$PROJECT_DIR = $(git rev-parse --show-toplevel)
$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName
$BUILD_DIR = "$PROJECT_DIR\pkg\windows\build"
$BUILDENV_DIR = "$PROJECT_DIR\pkg\windows\buildenv"
$TESTS_DIR = "$SCRIPT_DIR\config_tests"
#-------------------------------------------------------------------------------
# Script Functions
#-------------------------------------------------------------------------------
function Write-Result($result, $ForegroundColor="Green") {
$position = 80 - $result.Length - [System.Console]::CursorLeft
Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "")
}
#-------------------------------------------------------------------------------
# Script Begin
#-------------------------------------------------------------------------------
Write-Host $("=" * 80)
Write-Host "Clean the Test Environment" -ForegroundColor Cyan
Write-Host $("-" * 80)
#-------------------------------------------------------------------------------
# Delete Files
#-------------------------------------------------------------------------------
$delete_files = "*.bat",
"*.install.log",
"*.output",
"*.uninstall.log",
"*.un~"
$delete_files | ForEach-Object {
if ( Test-Path -Path "$TESTS_DIR\$_" ) {
Write-Host "Deleting $_`: " -NoNewline
Remove-Item -Path "$TESTS_DIR\$_" -Force -Recurse -ErrorAction SilentlyContinue
if (!(Test-Path -Path "$TESTS_DIR\$_")) {
Write-Result "Success"
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
}
}
#-------------------------------------------------------------------------------
# Delete Build Directories
#-------------------------------------------------------------------------------
$delete_dirs = $BUILD_DIR,
$BUILDENV_DIR
$delete_dirs | ForEach-Object {
if ( Test-Path -Path "$_" ) {
Write-Host "Deleting $_`: " -NoNewline
Remove-Item -Path "$_" -Force -Recurse
if ( ! (Test-Path -Path "$_") ) {
Write-Result "Success"
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
}
}
#-------------------------------------------------------------------------------
# Script Complete
#-------------------------------------------------------------------------------
Write-Host $("-" * 80)
Write-Host "Prepare the Test Environment Complete" -ForegroundColor Cyan
Write-Host $("=" * 80)

View file

@ -1,7 +0,0 @@
@ echo off
del *.bat
del *.install.log
del *.output
del *.uninstall.log
del *.un~

View file

@ -1 +1,3 @@
PowerShell -ExecutionPolicy RemoteSigned -File test.ps1
@ echo off
Set "CurDir=%~dp0"
PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\test.ps1"

View file

@ -1,8 +1,13 @@
Set-PSDebug -Strict
Set-strictmode -version latest
Set-StrictMode -Version latest
$oldrootdir = "C:\Salt"
$newrootdir = "C:\ProgramData\Salt Project\Salt"
$PROJECT_DIR = Resolve-Path -Path $(git rev-parse --show-toplevel)
$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName
$BUILD_DIR = "$PROJECT_DIR\pkg\windows\build"
$MSI_DIR = "$PROJECT_DIR\pkg\windows\msi"
$TEST_MSI = "$MSI_DIR\test.msi"
$OLD_ROOT_DIR = "C:\Salt"
$NEW_ROOT_DIR = "C:\ProgramData\Salt Project\Salt"
#==============================================================================
# Check for Salt installation
@ -16,13 +21,13 @@ if (Test-Path $scrambled_salt_upgradecode) {
#==============================================================================
# Check for Salt folders
#==============================================================================
if (Test-Path $newrootdir) {
Write-Host -ForegroundColor Red "`"$newrootdir`" must not exist"
if (Test-Path $NEW_ROOT_DIR) {
Write-Host -ForegroundColor Red "`"$NEW_ROOT_DIR`" must not exist"
exit 1
}
if (Test-Path $oldrootdir) {
Write-Host -ForegroundColor Red "$oldrootdir must not exist"
if (Test-Path $OLD_ROOT_DIR) {
Write-Host -ForegroundColor Red "$OLD_ROOT_DIR must not exist"
exit 1
}
@ -32,33 +37,35 @@ if (Test-Path *.output) {
}
$msis = Get-ChildItem ..\..\*.msi
$MSIs = Get-ChildItem "$BUILD_DIR\*.msi"
$nof_msis = ($msis | Measure-Object).Count
$MSI_COUNT = ($MSIs | Measure-Object).Count
if ($nof_msis -eq 0) {
if ($MSI_COUNT -eq 0) {
Write-Host -ForegroundColor Red *.msi must exist
exit 1
}
if ($nof_msis -gt 1) {
if ($MSI_COUNT -gt 1) {
Write-Host -ForegroundColor Red Only one *.msi must exist
exit 1
}
$msi = $msis[0]
Write-Host -ForegroundColor Yellow Testing ([System.IO.Path]::GetFileName($msi))
Copy-Item -Path $msi -Destination "test.msi"
$MSI = $MSIs[0]
Write-Host -ForegroundColor Yellow Testing ([System.IO.Path]::GetFileName($MSI))
Copy-Item -Path $MSI -Destination $TEST_MSI
$array_allowed_test_words = "dormant", "properties"
$exit_code = 0
foreach ($testfilename in Get-ChildItem *.test) {
foreach ( $testfilename in Get-ChildItem "$SCRIPT_DIR\*.test" ) {
$dormant = $false # test passes if and only if configuration is deleted on uninstall
$rootdir = $newrootdir # default for each test
$rootdir = $NEW_ROOT_DIR # default for each test
$test_name = $testfilename.basename
$batchfile = $test_name + ".bat"
$config_input = $test_name + ".input"
$minion_id = $test_name + ".minion_id"
$batchfile = "$SCRIPT_DIR\$test_name.bat"
$config_input = "$SCRIPT_DIR\$test_name.input"
$minion_id = "$SCRIPT_DIR\$test_name.minion_id"
$expected = "$SCRIPT_DIR\$test_name.expected"
$generated = "$SCRIPT_DIR\$test_name.output"
Write-Host -ForegroundColor Yellow -NoNewline ("{0,-65}" -f $test_name)
foreach($line in Get-Content $testfilename) {
@ -75,9 +82,9 @@ foreach ($testfilename in Get-ChildItem *.test) {
$dormant = $true
}
if ($head -eq "properties") {
Set-Content -Path $batchfile -Value "msiexec /i $msi $tail /l*v $test_name.install.log /qb"
Set-Content -Path $batchfile -Value "msiexec /i $TEST_MSI $tail /l*v `"$SCRIPT_DIR\$test_name.install.log`" /qb"
if($tail.Contains("ROOTDIR=c:\salt")){
$rootdir = $oldrootdir
$rootdir = $OLD_ROOT_DIR
}
}
} else {
@ -114,8 +121,6 @@ foreach ($testfilename in Get-ChildItem *.test) {
}
# Compare expected and generated configuration
$expected = $test_name + ".expected"
$generated = $test_name + ".output"
Copy-Item -Path "$rootdir\conf\minion" -Destination $generated
if((Get-Content -Raw $expected) -eq (Get-Content -Raw $generated)){
@ -132,10 +137,10 @@ foreach ($testfilename in Get-ChildItem *.test) {
"FilePath" = "$Env:SystemRoot\system32\msiexec.exe"
"ArgumentList" = @(
"/X"
"test.msi"
"$TEST_MSI"
"/qb"
"/l*v"
"$test_name.uninstall.log"
"$SCRIPT_DIR\$test_name.uninstall.log"
)
"Verb" = "runas"
"PassThru" = $true
@ -157,12 +162,12 @@ foreach ($testfilename in Get-ChildItem *.test) {
}
# Clean up system from the last test config
Remove-Item -Path $oldrootdir -Recurse -Force -ErrorAction Ignore | Out-Null
Remove-Item -Path $newrootdir -Recurse -Force -ErrorAction Ignore | Out-Null
Remove-Item -Path $OLD_ROOT_DIR -Recurse -Force -ErrorAction Ignore | Out-Null
Remove-Item -Path $NEW_ROOT_DIR -Recurse -Force -ErrorAction Ignore | Out-Null
}
# Clean up copied msi
Remove-Item test.msi
Remove-Item $TEST_MSI
if ($exit_code -eq 0) {
Write-Host "All tests completed successfully" -ForegroundColor Green

View file

@ -1,3 +0,0 @@
master: custom
id: also_custom
another: custom_field

View file

@ -0,0 +1,3 @@
@ echo off
Set "CurDir=%~dp0"
PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\setup.ps1" %*

View file

@ -0,0 +1,87 @@
# Set up the environment for testing
#-------------------------------------------------------------------------------
# Script Variables
#-------------------------------------------------------------------------------
$PROJECT_DIR = $(git rev-parse --show-toplevel)
$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName
$BUILD_DIR = "$PROJECT_DIR\pkg\windows\build"
$BUILDENV_DIR = "$PROJECT_DIR\pkg\windows\buildenv"
$MSI_DIR = "$PROJECT_DIR\pkg\windows\msi"
$BUILD_SCRIPT = "$MSI_DIR\build_pkg.ps1"
#-------------------------------------------------------------------------------
# Script Functions
#-------------------------------------------------------------------------------
function Write-Result($result, $ForegroundColor="Green") {
$position = 80 - $result.Length - [System.Console]::CursorLeft
Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "")
}
#-------------------------------------------------------------------------------
# Script Begin
#-------------------------------------------------------------------------------
Write-Host $("=" * 80)
Write-Host "Prepare the Test Environment" -ForegroundColor Cyan
Write-Host $("-" * 80)
#-------------------------------------------------------------------------------
# Create Mock Directories
#-------------------------------------------------------------------------------
Write-Host "Creating mock build directory: " -NoNewline
New-Item -Path $BUILD_DIR -ItemType Directory | Out-Null
if ( Test-Path -Path $BUILD_DIR ) {
Write-Result "Success" -ForegroundColor Green
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
Write-Host "Creating mock buildenv directory: " -NoNewline
New-Item -Path $BUILDENV_DIR -ItemType Directory | Out-Null
if ( Test-Path -Path $BUILDENV_DIR ) {
Write-Result "Success" -ForegroundColor Green
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
#-------------------------------------------------------------------------------
# Copy Mock Files
#-------------------------------------------------------------------------------
Write-Host "Copying mock files: " -NoNewLine
Copy-Item -Path "$SCRIPT_DIR\_mock_files\buildenv\*" `
-Destination "$BUILDENV_DIR\" `
-Recurse -Force | Out-Null
if ( Test-Path -Path "$BUILDENV_DIR\salt-minion.exe" ) {
Write-Result "Success"
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
#-------------------------------------------------------------------------------
# Build Test MSI
#-------------------------------------------------------------------------------
Write-Host "Building test MSI: " -NoNewLine
. "$BUILD_SCRIPT" | Out-Null
if ( Test-Path -Path "$BUILD_DIR\*.msi" ) {
Write-Result "Success"
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
#-------------------------------------------------------------------------------
# Script Complete
#-------------------------------------------------------------------------------
Write-Host $("-" * 80)
Write-Host "Prepare the Test Environment Complete" -ForegroundColor Cyan
Write-Host $("=" * 80)

View file

@ -0,0 +1,3 @@
@ echo off
Set "CurDir=%~dp0"
PowerShell -ExecutionPolicy RemoteSigned -File "%CurDir%\config_tests\test.ps1"

View file

@ -1 +0,0 @@
PowerShell -ExecutionPolicy RemoteSigned -File uninst-by-UpgradeCode.ps1

View file

@ -1,29 +0,0 @@
# Uninstalls the Salt-Minion using the msi upgrade code
$upgradecodeRegKey = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes\2A3BF6CFED569A14DA191DA004B26D14'
if (Test-Path $upgradecodeRegKey) { # The scrambled product code is the only entry
$scrambledProductcode = $((Get-ItemProperty $upgradecodeRegKey).PSObject.Properties)[0].Name.ToString()
if ($scrambledProductcode -match '^[0-9A-Z]{32}$') { # Reverse chunks
#Write-Host -ForegroundColor Yellow $scrambledProductcode.Insert(20,'-').Insert(16,'-').Insert(12,'-').Insert(8,'-')
$productcode = ""
$lastIndex = 0
foreach ($index in @(8, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2)) {
$chunk = $scrambledProductcode.Substring($lastIndex, $index) -split ''
[array]::Reverse($chunk)
$productcode += $chunk -join ''
$lastIndex += $index
}
# Format productcode with dashes and curly braces
$productcode = $productcode.Insert(20,'-').Insert(16,'-').Insert(12,'-').Insert(8,'-')
$productcode = "{$productcode}"
Write-Host -ForegroundColor Yellow msiexec...
$msiexitcode = (Start-Process -FilePath "msiexec.exe" -ArgumentList "/x $productcode /qb" -Wait -Passthru).ExitCode
Write-Host -ForegroundColor Yellow "msiexec... exited with code $msiexitcode"
} else {
Write-Host -ForegroundColor Red Cannot uninstall
exit(1)
}
} else {
Write-Host -ForegroundColor Blue Not installed
}

View file

@ -1 +0,0 @@
msiexec /x %* /qb! /l*v %1-uninstall.log

View file

@ -33,7 +33,7 @@ function Write-Result($result, $ForegroundColor="Green") {
}
#-------------------------------------------------------------------------------
# Variables
# Script Variables
#-------------------------------------------------------------------------------
$PROJECT_DIR = $(git rev-parse --show-toplevel)