Skip to content

Instantly share code, notes, and snippets.

@nicholasdille
Created November 25, 2015 09:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasdille/7583617d6a271b5e8623 to your computer and use it in GitHub Desktop.
Save nicholasdille/7583617d6a271b5e8623 to your computer and use it in GitHub Desktop.
Example of #PSDSC using #Pester for validating configuration data
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = 'sql-01'
Roles = @{
Computer = @{
MachineName = 'sql-01'
DomainName = 'example.com'
Credential = 'Svc-Domain-Join@example.com'
}
}
}
)
Credentials = @{
'Svc-Domain-Join@example.com' = (Join-Path -Path $PSScriptRoot -ChildPath 'ConfigDataPester.clixml')
}
}
# Mimic special variables in PSDSC configurations
$AllNodes = $ConfigurationData.AllNodes
Describe 'Structural Tests' {
It 'Defines credential files' {
$ConfigurationData.Keys -icontains 'Credentials' | Should Be $true
}
foreach ($CredName in $ConfigurationData.Credentials.Keys) {
It "Defines existing credential file for $CredName" {
Test-Path -Path $ConfigurationData.Credentials.$CredName | Should Be $true
}
}
}
# Mimic special variable $Node in enumeration
foreach ($Node in $ConfigurationData.AllNodes) {
Describe "Node $($Node.NodeName)" {
Context 'Role computer' {
It 'Contains computer role' {
$Node.Roles.Keys -icontains 'Computer' | Should Be $true
}
It 'Resolves credential object if specified' {
if ($Node.Roles.Computer.Keys -icontains 'Credential') {
$ConfigurationData.Credentials.Keys -icontains $Node.Roles.Computer.Credential | Should Be $true
}
}
It 'Specifies credentials for domain join' {
$Node.Roles.Computer.Keys -icontains 'DomainName' | Should Be $true
$Node.Roles.Computer.Keys -icontains 'Credential' | Should Be $true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment