Update module version to 1.0.1 and add new functions for exporting and deploying DSC configuration data
This commit is contained in:
@@ -117,4 +117,175 @@ Describe 'Merge-DSCConfigurationData Extends' {
|
||||
|
||||
{ Merge-DSCConfigurationData -Path $APath } | Should Throw
|
||||
}
|
||||
|
||||
It 'exports importable PSD1 files with quoted metadata keys' {
|
||||
$Path = Join-Path -Path $TestDrive -ChildPath 'Export.psd1'
|
||||
|
||||
@{
|
||||
Metadata = @{
|
||||
Description = @{
|
||||
'de-DE' = 'Deutsch'
|
||||
'en-US' = 'English'
|
||||
}
|
||||
}
|
||||
} | Export-PowerShellDataFile -Path $Path -Force
|
||||
|
||||
$Data = Import-PowerShellDataFile -Path $Path
|
||||
$Data.Metadata.Description['de-DE'] | Should Be 'Deutsch'
|
||||
$Data.Metadata.Description['en-US'] | Should Be 'English'
|
||||
}
|
||||
|
||||
It 'creates materialized deployment data without exporting by default' {
|
||||
$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
|
||||
}
|
||||
}
|
||||
Resources = @{
|
||||
AllNodes = @(
|
||||
@{
|
||||
NodeName = '*'
|
||||
PSDSCAllowPlainTextPassword = $true
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
'@ | Set-Content -Path $DefaultPath -Encoding UTF8
|
||||
|
||||
@'
|
||||
@{
|
||||
Metadata = @{
|
||||
TemplateType = 'Environment'
|
||||
Name = 'Contoso'
|
||||
Extends = './Default.psd1'
|
||||
}
|
||||
Parameters = @{
|
||||
DomainFQDN = @{
|
||||
Value = 'contoso.local'
|
||||
}
|
||||
}
|
||||
}
|
||||
'@ | Set-Content -Path $ChildPath -Encoding UTF8
|
||||
|
||||
$Result = New-DSCConfigurationDataDeployment `
|
||||
-Name 'Contoso-Test' `
|
||||
-DeploymentId '123' `
|
||||
-SourceTemplatePath $ChildPath `
|
||||
-AllNodes @(
|
||||
@{
|
||||
NodeName = 'Node01'
|
||||
RunCentralAdministration = $true
|
||||
}
|
||||
)
|
||||
|
||||
$Result.Metadata.TemplateType | Should Be 'Deployment'
|
||||
$Result.Metadata.Sources.Files.Count | Should Be 2
|
||||
$Result.Parameters.DomainFQDN.Value | Should Be 'contoso.local'
|
||||
$Result.Resources.AllNodes[0].NodeName | Should Be 'Node01'
|
||||
$Result.Resources.AllNodes[0].PSDSCAllowPlainTextPassword | Should Be $true
|
||||
}
|
||||
|
||||
It 'exports materialized deployment data as PSD1' {
|
||||
$DefaultPath = Join-Path -Path $TestDrive -ChildPath 'Default.psd1'
|
||||
$ChildPath = Join-Path -Path $TestDrive -ChildPath 'Contoso.psd1'
|
||||
$DeploymentPath = Join-Path -Path $TestDrive -ChildPath 'Deployments\Deployment_123.psd1'
|
||||
|
||||
@'
|
||||
@{
|
||||
Metadata = @{
|
||||
TemplateType = 'Environment'
|
||||
Name = 'Default'
|
||||
}
|
||||
Parameters = @{
|
||||
DomainFQDN = @{
|
||||
Type = 'string'
|
||||
Required = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
'@ | Set-Content -Path $DefaultPath -Encoding UTF8
|
||||
|
||||
@'
|
||||
@{
|
||||
Metadata = @{
|
||||
TemplateType = 'Environment'
|
||||
Name = 'Contoso'
|
||||
Extends = './Default.psd1'
|
||||
}
|
||||
Parameters = @{
|
||||
DomainFQDN = @{
|
||||
Value = 'contoso.local'
|
||||
}
|
||||
}
|
||||
}
|
||||
'@ | Set-Content -Path $ChildPath -Encoding UTF8
|
||||
|
||||
$Result = New-DSCConfigurationDataDeployment `
|
||||
-Path $DeploymentPath `
|
||||
-Name 'Contoso-Test' `
|
||||
-DeploymentId '123' `
|
||||
-SourceTemplatePath $ChildPath `
|
||||
-AllNodes @(
|
||||
@{
|
||||
NodeName = 'Node01'
|
||||
RunCentralAdministration = $true
|
||||
}
|
||||
) `
|
||||
-UseRelativePaths `
|
||||
-Export `
|
||||
-Format PowerShellDataFile `
|
||||
-Force `
|
||||
-PassThru
|
||||
|
||||
$DeploymentPath | Should Exist
|
||||
$Result.ConfigurationData.Metadata.TemplateType | Should Be 'Deployment'
|
||||
$Result.ConfigurationData.Metadata.Sources.Files.Count | Should Be 2
|
||||
$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
|
||||
|
||||
$Imported = Import-PowerShellDataFile -Path $DeploymentPath
|
||||
$Imported.Metadata.Name | Should Be 'Contoso-Test'
|
||||
$Imported.Metadata.Sources.Templates.Count | Should Be 1
|
||||
}
|
||||
|
||||
It 'exports materialized deployment data as JSON' {
|
||||
$DefaultPath = Join-Path -Path $TestDrive -ChildPath 'Default.psd1'
|
||||
$DeploymentPath = Join-Path -Path $TestDrive -ChildPath 'Deployment_123.json'
|
||||
|
||||
@'
|
||||
@{
|
||||
Parameters = @{
|
||||
DomainFQDN = @{
|
||||
Type = 'string'
|
||||
Value = 'contoso.local'
|
||||
}
|
||||
}
|
||||
}
|
||||
'@ | Set-Content -Path $DefaultPath -Encoding UTF8
|
||||
|
||||
New-DSCConfigurationDataDeployment `
|
||||
-Path $DeploymentPath `
|
||||
-Name 'Contoso-Test' `
|
||||
-DeploymentId '123' `
|
||||
-SourceTemplatePath $DefaultPath `
|
||||
-Export `
|
||||
-Format Json `
|
||||
-Force
|
||||
|
||||
$DeploymentPath | Should Exist
|
||||
$Imported = Get-Content -Path $DeploymentPath -Raw | ConvertFrom-Json
|
||||
$Imported.Metadata.TemplateType | Should Be 'Deployment'
|
||||
$Imported.Parameters.DomainFQDN.Value | Should Be 'contoso.local'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user