From aa5d5eea28547ca33286afc95413e185beb8962a Mon Sep 17 00:00:00 2001 From: Torsten Brendgen Date: Tue, 21 Apr 2026 13:07:57 +0200 Subject: [PATCH] adding Pester Tests --- .gitignore | 2 +- Tests/Merge-ConfigurationData.Tests.ps1 | 132 ------------------------ 2 files changed, 1 insertion(+), 133 deletions(-) delete mode 100644 Tests/Merge-ConfigurationData.Tests.ps1 diff --git a/.gitignore b/.gitignore index 942936b..877df7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .git .sample -.output \ No newline at end of file +.tests \ No newline at end of file diff --git a/Tests/Merge-ConfigurationData.Tests.ps1 b/Tests/Merge-ConfigurationData.Tests.ps1 deleted file mode 100644 index 1d73b2a..0000000 --- a/Tests/Merge-ConfigurationData.Tests.ps1 +++ /dev/null @@ -1,132 +0,0 @@ -$script:ModuleRoot = Split-Path -Parent $PSScriptRoot -$script:SampleRoot = Join-Path -Path $script:ModuleRoot -ChildPath ".sample" - -Import-Module (Join-Path -Path $script:ModuleRoot -ChildPath "Merge-DSCConfigurationData.psd1") -Force - -Describe "Merge-ConfigurationData" { - It "merges wildcard instance templates into all deployment instances" { - $Template = Import-PowerShellDataFile (Join-Path -Path $script:SampleRoot -ChildPath "Template.psd1") - $Deployment = Import-PowerShellDataFile (Join-Path -Path $script:SampleRoot -ChildPath "Deployment.psd1") - - $Result = Merge-ConfigurationData -Template $Template -Deployment $Deployment - $Instances = @($Result.NonNodeData.Services.SQLServer.Instances) - - $Instances.Count | Should Be 2 - ($Instances.Name -contains "*") | Should Be $false - - foreach($Name in @("MSSQLSERVER", "MSSQLSERVERTEST")){ - $Instance = $Instances | Where-Object { $_.Name -eq $Name } - - $Instance | Should Not BeNullOrEmpty - $Instance.Features | Should Be "SQLENGINE,FULLTEXT" - $Instance.ConfigurationOptions.Count | Should Be 4 - $Instance.AdditionalScripts.Count | Should Be 6 - $Instance.Memory | Should Not BeNullOrEmpty - $Instance.Directories | Should Not BeNullOrEmpty - } - } - - It "does not merge an exact instance template into another instance name" { - $Template = @{ - NonNodeData = @{ - Services = @{ - SQLServer = @{ - Instances = @( - @{ - Name = "MSSQLSERVER" - Marker = "exact-only" - } - ) - } - } - } - } - - $Deployment = @{ - NonNodeData = @{ - Services = @{ - SQLServer = @{ - Instances = @( - @{ Name = "MSSQLSERVER" }, - @{ Name = "MSSQLSERVERTEST" } - ) - } - } - } - } - - $Result = Merge-ConfigurationData -Template $Template -Deployment $Deployment - $Instances = @($Result.NonNodeData.Services.SQLServer.Instances) - - ($Instances | Where-Object { $_.Name -eq "MSSQLSERVER" }).Marker | Should Be "exact-only" - ($Instances | Where-Object { $_.Name -eq "MSSQLSERVERTEST" }).Marker | Should BeNullOrEmpty - } - - It "uses the name-key fallback for unknown arrays" { - $Template = @{ - Databases = @( - @{ - DatabaseName = "AppDb" - RecoveryModel = "Full" - } - ) - } - - $Deployment = @{ - Databases = @( - @{ - DatabaseName = "AppDb" - Owner = "dbo" - }, - @{ - DatabaseName = "LogDb" - Owner = "dbo" - } - ) - } - - $Result = Merge-ConfigurationData -Template $Template -Deployment $Deployment - $Databases = @($Result.Databases) - - ($Databases | Where-Object { $_.DatabaseName -eq "AppDb" }).RecoveryModel | Should Be "Full" - ($Databases | Where-Object { $_.DatabaseName -eq "LogDb" }).RecoveryModel | Should BeNullOrEmpty - } - - It "uses Key and ValueName together for registry array merges" { - $Template = @{ - Basic = @{ - Registry = @( - @{ - Key = "K1" - ValueName = "Enabled" - Default = "Template-K1" - }, - @{ - Key = "K2" - ValueName = "Enabled" - Default = "Template-K2" - } - ) - } - } - - $Deployment = @{ - Basic = @{ - Registry = @( - @{ - Key = "K1" - ValueName = "Enabled" - ValueData = "Deployment-K1" - } - ) - } - } - - $Result = Merge-ConfigurationData -Template $Template -Deployment $Deployment - $Registry = @($Result.Basic.Registry) - - ($Registry | Where-Object { $_.Key -eq "K1" }).Default | Should Be "Template-K1" - ($Registry | Where-Object { $_.Key -eq "K1" }).ValueData | Should Be "Deployment-K1" - ($Registry | Where-Object { $_.Key -eq "K2" }).Default | Should Be "Template-K2" - } -}