Update configs.Tests.ps1

This commit is contained in:
Chris Titus 2024-08-28 16:03:49 -05:00
parent 31ec62f00b
commit be9fae199c

View File

@ -9,7 +9,7 @@ Get-ChildItem .\config | Where-Object {$_.Extension -eq ".json"} | ForEach-Objec
# Tests - Application Installs # Tests - Application Installs
#=========================================================================== #===========================================================================
Describe "Config Files" -ForEach @( $configurations = @(
@{ @{
name = "applications" name = "applications"
config = $('{ config = $('{
@ -25,57 +25,64 @@ Describe "Config Files" -ForEach @(
name = "tweaks" name = "tweaks"
undo = $true undo = $true
} }
) { )
Context "$name config file" {
It "Imports with no errors" {
$global:importedconfigs.$name | should -Not -BeNullOrEmpty
}
if ($config) {
It "Imports should be the correct structure" {
$applications = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
$template = $config | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
$result = New-Object System.Collections.Generic.List[System.Object]
Foreach ($application in $applications) {
$compare = $global:importedconfigs.$name.$application | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
if ($(Compare-Object $compare $template) -ne $null) {
$result.Add($application)
}
}
$result | Select-String "WPF*" | should -BeNullOrEmpty foreach ($configuration in $configurations) {
Describe "Config Files - $($configuration.name)" {
$name = $configuration.name
$config = $configuration.config
$undo = $configuration.undo
Context "$name config file" {
It "Imports with no errors" {
$global:importedconfigs.$name | should -Not -BeNullOrEmpty
} }
} if ($config) {
if($undo) { It "Imports should be the correct structure" {
It "Tweaks should contain original Value" { $applications = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
$tweaks = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name $template = $config | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
$result = New-Object System.Collections.Generic.List[System.Object] $result = New-Object System.Collections.Generic.List[System.Object]
Foreach ($application in $applications) {
foreach ($tweak in $tweaks) { $compare = $global:importedconfigs.$name.$application | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
$Originals = @( if ($(Compare-Object $compare $template) -ne $null) {
@{ $result.Add($application)
name = "registry"
value = "OriginalValue"
},
@{
name = "service"
value = "OriginalType"
},
@{
name = "ScheduledTask"
value = "OriginalState"
}
)
Foreach ($original in $Originals) {
$TotalCount = ($global:importedconfigs.$name.$tweak.$($original.name)).count
$OriginalCount = ($global:importedconfigs.$name.$tweak.$($original.name).$($original.value) | Where-Object {$_}).count
if($TotalCount -ne $OriginalCount) {
$result.Add("$Tweak,$($original.name)")
} }
} }
$result | Select-String "WPF*" | should -BeNullOrEmpty
}
}
if($undo) {
It "Tweaks should contain original Value" {
$tweaks = $global:importedconfigs.$name | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name
$result = New-Object System.Collections.Generic.List[System.Object]
foreach ($tweak in $tweaks) {
$Originals = @(
@{
name = "registry"
value = "OriginalValue"
},
@{
name = "service"
value = "OriginalType"
},
@{
name = "ScheduledTask"
value = "OriginalState"
}
)
Foreach ($original in $Originals) {
$TotalCount = ($global:importedconfigs.$name.$tweak.$($original.name)).count
$OriginalCount = ($global:importedconfigs.$name.$tweak.$($original.name).$($original.value) | Where-Object {$_}).count
if($TotalCount -ne $OriginalCount) {
$result.Add("$Tweak,$($original.name)")
}
}
}
$result | Select-String "WPF*" | should -BeNullOrEmpty
} }
$result | Select-String "WPF*" | should -BeNullOrEmpty
} }
} }
} }
} }