$script:ModuleRoot = Split-Path -Parent $PSScriptRoot $script:ModuleManifest = Join-Path -Path $script:ModuleRoot -ChildPath 'Merge-DSCConfigurationData.psd1' Import-Module $script:ModuleManifest -Force Describe 'Merge-DSCConfigurationData Extends' { It 'keeps the existing hashtable merge behavior' { $Template = @{ Parameters = @{ DomainFQDN = @{ Type = 'string' Required = $true DefaultValue = 'example.local' } } } $Deployment = @{ Parameters = @{ DomainFQDN = @{ Value = 'contoso.local' } } } $Result = Merge-DSCConfigurationData -Template $Template -Deployment $Deployment $Result.Parameters.DomainFQDN.Type | Should Be 'string' $Result.Parameters.DomainFQDN.Required | Should Be $true $Result.Parameters.DomainFQDN.Value | Should Be 'contoso.local' } It 'merges a child template with Metadata.Extends' { $DefaultPath = Join-Path -Path $TestDrive -ChildPath 'Default.psd1' $ChildPath = Join-Path -Path $TestDrive -ChildPath 'Contoso.psd1' @' @{ Metadata = @{ TemplateType = 'Environment' Name = 'Default' } Parameters = @{ DomainFQDN = @{ Type = 'string' Required = $true DefaultValue = 'example.local' } DomainNetBIOS = @{ Type = 'string' Required = $true } } Resources = @{ NonNodeData = @{ RequiredModules = @( @{ Name = 'ActiveDirectoryDsc' Version = '6.7.1' } ) } } } '@ | Set-Content -Path $DefaultPath -Encoding UTF8 @' @{ Metadata = @{ TemplateType = 'Environment' Name = 'Contoso' Extends = './Default.psd1' } Parameters = @{ DomainFQDN = @{ Value = 'contoso.local' } DomainNetBIOS = @{ Value = 'CONTOSO' } } } '@ | Set-Content -Path $ChildPath -Encoding UTF8 $Result = Merge-DSCConfigurationData -Path $ChildPath -PassThru $Result.Files.Count | Should Be 2 [System.IO.Path]::GetFileName($Result.Files[0]) | Should Be 'Default.psd1' [System.IO.Path]::GetFileName($Result.Files[1]) | Should Be 'Contoso.psd1' $Result.ConfigurationData.Parameters.DomainFQDN.Type | Should Be 'string' $Result.ConfigurationData.Parameters.DomainFQDN.Value | Should Be 'contoso.local' $Result.ConfigurationData.Parameters.DomainNetBIOS.Required | Should Be $true $Result.ConfigurationData.Parameters.DomainNetBIOS.Value | Should Be 'CONTOSO' $Result.ConfigurationData.Resources.NonNodeData.RequiredModules[0].Name | Should Be 'ActiveDirectoryDsc' $Result.ConfigurationData.ContainsKey('Metadata') | Should Be $false } It 'detects circular Metadata.Extends references' { $APath = Join-Path -Path $TestDrive -ChildPath 'A.psd1' $BPath = Join-Path -Path $TestDrive -ChildPath 'B.psd1' @' @{ Metadata = @{ Extends = './B.psd1' } } '@ | Set-Content -Path $APath -Encoding UTF8 @' @{ Metadata = @{ Extends = './A.psd1' } } '@ | Set-Content -Path $BPath -Encoding UTF8 { Merge-DSCConfigurationData -Path $APath } | Should Throw } }