Creating Module

This commit is contained in:
Torsten Brendgen
2026-04-21 13:02:51 +02:00
parent 7c9b854aec
commit e10ab48bb4
14 changed files with 493 additions and 321 deletions

View File

@@ -0,0 +1,132 @@
$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"
}
}