Created
November 25, 2015 09:29
-
-
Save nicholasdille/7583617d6a271b5e8623 to your computer and use it in GitHub Desktop.
Example of #PSDSC using #Pester for validating configuration data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ConfigurationData = @{ | |
AllNodes = @( | |
@{ | |
NodeName = 'sql-01' | |
Roles = @{ | |
Computer = @{ | |
MachineName = 'sql-01' | |
DomainName = 'example.com' | |
Credential = '[email protected]' | |
} | |
} | |
} | |
) | |
Credentials = @{ | |
'[email protected]' = (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