Add Test-DSCConfigurationDataDeployment function and related enhancements

This commit is contained in:
Torsten Brendgen
2026-07-03 12:34:48 +02:00
parent fb9209456b
commit c93f4ebc5c
7 changed files with 242 additions and 7 deletions

View File

@@ -212,6 +212,8 @@ Describe 'Merge-DSCConfigurationData Extends' {
Required = $true
}
}
Variables = @{
}
}
'@ | Set-Content -Path $DefaultPath -Encoding UTF8
@@ -250,6 +252,8 @@ Describe 'Merge-DSCConfigurationData Extends' {
$DeploymentPath | Should Exist
$Result.ConfigurationData.Metadata.TemplateType | Should Be 'Deployment'
$Result.ConfigurationData.Metadata.Sources.Files.Count | Should Be 2
$Result.ConfigurationData.Metadata.Sources.Files[0].Hash.Length | Should Be 64
$Result.ConfigurationData.Metadata.Sources.Files[0].Algorithm | Should Be 'SHA256'
$Result.ConfigurationData.Parameters.DomainFQDN.Value | Should Be 'contoso.local'
$Result.ConfigurationData.Resources.AllNodes[0].NodeName | Should Be 'Node01'
$Result.ConfigurationData.Resources.AllNodes[0].RunCentralAdministration | Should Be $true
@@ -257,6 +261,10 @@ Describe 'Merge-DSCConfigurationData Extends' {
$Imported = Import-PowerShellDataFile -Path $DeploymentPath
$Imported.Metadata.Name | Should Be 'Contoso-Test'
$Imported.Metadata.Sources.Templates.Count | Should Be 1
$Validation = Test-DSCConfigurationDataDeployment -Path $DeploymentPath -PassThru
$Validation.IsValid | Should Be $true
$Validation.IsStale | Should Be $false
}
It 'exports materialized deployment data as JSON' {
@@ -271,6 +279,8 @@ Describe 'Merge-DSCConfigurationData Extends' {
Value = 'contoso.local'
}
}
Variables = @{
}
}
'@ | Set-Content -Path $DefaultPath -Encoding UTF8
@@ -288,4 +298,53 @@ Describe 'Merge-DSCConfigurationData Extends' {
$Imported.Metadata.TemplateType | Should Be 'Deployment'
$Imported.Parameters.DomainFQDN.Value | Should Be 'contoso.local'
}
It 'detects changed deployment source files by hash' {
$DefaultPath = Join-Path -Path $TestDrive -ChildPath 'Default.psd1'
$DeploymentPath = Join-Path -Path $TestDrive -ChildPath 'Deployment_123.psd1'
@'
@{
Parameters = @{
DomainFQDN = @{
Type = 'string'
Value = 'contoso.local'
}
}
Variables = @{
}
}
'@ | Set-Content -Path $DefaultPath -Encoding UTF8
New-DSCConfigurationDataDeployment `
-Path $DeploymentPath `
-Name 'Contoso-Test' `
-DeploymentId '123' `
-SourceTemplatePath $DefaultPath `
-AllNodes @(
@{
NodeName = 'Node01'
}
) `
-Export `
-Force
@'
@{
Parameters = @{
DomainFQDN = @{
Type = 'string'
Value = 'changed.local'
}
}
Variables = @{
}
}
'@ | Set-Content -Path $DefaultPath -Encoding UTF8
$Validation = Test-DSCConfigurationDataDeployment -Path $DeploymentPath -PassThru
$Validation.IsValid | Should Be $true
$Validation.IsStale | Should Be $true
@($Validation.Issues | Where-Object { $_.Code -eq 'SourceChanged' }).Count | Should Be 1
}
}