Skip to content

Commit 3e714f6

Browse files
committed
Update tests in Install-Defaults
Updated Install-Defaults.Tests.ps1 to remove suppress message attributes and changed the script execution test to assert no exceptions are thrown instead of checking for a return value of 0. Added #region and #endregion comments to organize sections in Install-Defaults.ps1 for improved readability.
1 parent e76b239 commit 3e714f6

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/Install-Defaults.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ if (!([System.Environment]::Is64BitProcess)) {
105105
}
106106
#endregion
107107

108-
# Configure the environment
108+
#region Configure the environment
109109
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
110110
$InformationPreference = [System.Management.Automation.ActionPreference]::Continue
111111
$ProgressPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
@@ -124,6 +124,7 @@ $prefs = @{
124124
# Configure working path
125125
if ($Path.Length -eq 0) { $WorkingPath = $PWD.Path } else { $WorkingPath = $Path }
126126
Push-Location -Path $WorkingPath
127+
#endregion
127128

128129
#region Import functions
129130
$ModuleFile = $(Join-Path -Path $PSScriptRoot -ChildPath "Install-Defaults.psm1")
@@ -138,7 +139,7 @@ foreach ($Process in $PSProcesses) {
138139
Write-LogFile -Message "Running process: $($Process.CommandLine)"
139140
}
140141

141-
# Get system properties
142+
#region Get system properties
142143
$Platform = Get-Platform
143144

144145
$Build = ([System.Environment]::OSVersion.Version).Build
@@ -150,15 +151,17 @@ $OSName = Get-OSName
150151

151152
$DisplayVersion = Get-ChildItem -Path $WorkingPath -Include "VERSION.txt" -Recurse | Get-Content -Raw
152153
Write-LogFile -Message "Script version: $DisplayVersion"
154+
#endregion
153155

154156
#region Gather configs
155157
$AllConfigs = @(Get-ChildItem -Path "$WorkingPath\configs" -Include "*.All.json" -Recurse -ErrorAction "Continue")
156158
$ModelConfigs = @(Get-ChildItem -Path "$WorkingPath\configs" -Include "*.$Model.json" -Recurse -ErrorAction "Continue")
157159
$BuildConfigs = @(Get-ChildItem -Path "$WorkingPath\configs" -Include "*.$Build.json" -Recurse -ErrorAction "Continue")
158160
$PlatformConfigs = @(Get-ChildItem -Path "$WorkingPath\configs" -Include "*.$Platform.json" -Recurse -ErrorAction "Continue")
159161
Write-LogFile -Message "Found: $(($AllConfigs + $ModelConfigs + $BuildConfigs + $PlatformConfigs).Count) configs"
162+
#endregion
160163

161-
# Implement the settings defined in each config file
164+
#region Implement the settings defined in each config file
162165
foreach ($Config in ($AllConfigs + $PlatformConfigs + $BuildConfigs + $ModelConfigs)) {
163166

164167
# Read the settings JSON
@@ -276,7 +279,7 @@ else {
276279
}
277280
#endregion
278281

279-
# Copy the source files for use with upgrades
282+
#region Copy the source files for use with upgrades
280283
if (Test-Path -Path "$FeatureUpdatePath\Install-Defaults.ps1" -PathType "Leaf") {
281284
Write-LogFile -Message "Skipping copy to $FeatureUpdatePath"
282285
}
@@ -291,8 +294,9 @@ else {
291294
Write-LogFile -Message $_.Exception.Message -LogLevel 3
292295
}
293296
}
297+
#endregion
294298

295-
# Set uninstall registry value for detecting as an installed application
299+
#region Set uninstall registry value for detecting as an installed application
296300
$Key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
297301
New-Item -Path "$Key\{$Guid}" -Type "RegistryKey" -Force -ErrorAction "Continue" | Out-Null
298302
if ($PSCmdlet.ShouldProcess("Set uninstall key values")) {
@@ -303,6 +307,7 @@ if ($PSCmdlet.ShouldProcess("Set uninstall key values")) {
303307
Set-ItemProperty -Path "$Key\{$Guid}" -Name "SystemComponent" -Value 1 -Type "DWord" -Force -ErrorAction "Continue" | Out-Null
304308
Set-ItemProperty -Path "$Key\{$Guid}" -Name "HelpLink" -Value $HelpLink -Type "String" -Force -ErrorAction "Continue" | Out-Null
305309
}
310+
#endregion
306311

307312
# Write last entry to the event log and output 0 so that we don't fail image builds
308313
$EndTime = (Get-Date) - $StartTime

tests/Install-Defaults.Tests.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
.SYNOPSIS
33
Main Pester function tests.
44
#>
5-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
6-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "")]
75
[CmdletBinding()]
86
param()
97

@@ -30,7 +28,7 @@ Describe "Install script execution validation" {
3028
Language = "en-AU"
3129
TimeZone = "AUS Eastern Standard Time"
3230
}
33-
& $Script.FullName @params | Should -Be 0
31+
{ & $Script.FullName @params } | Should -Not -Throw
3432
Pop-Location
3533
}
3634
}

0 commit comments

Comments
 (0)