Skip to content

Commit

Permalink
Merge pull request #32 from alx9r/implement-Test-ConfigStep
Browse files Browse the repository at this point in the history
Implement test config step
  • Loading branch information
alx9r authored Jan 8, 2017
2 parents 1ada8d3 + c79e61b commit ccde9df
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 0.2.0

## 0.1.1 (2017-01-02)
- improve "Installing ZeroDSC Section" in documentation
- improve public appearance of `Import-DscResource`
Expand Down
56 changes: 56 additions & 0 deletions Functions/testConfigStep.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Import-Module ZeroDSC -Force

InModuleScope ZeroDSC {
Describe Test-ConfigStep {
foreach ( $values in @(
@('all complete', @('Complete','Complete'), $true, 2),
@('all pending', @('Pending','Pending'), $false, 1),
@('first pending', @('Pending','Complete'), $false, 1),
@('last pending', @('Complete','Pending'), $false, 2)
)
)
{
$testName,$results,$returnValue,$invokations = $values
Context $testName {
$q = [System.Collections.Queue]::new()
$a = [System.Collections.ArrayList]::new()
Mock Invoke-ConfigStep -Verifiable { return $q.Dequeue() }
It 'populate the results queue' {
foreach ( $result in $results )
{
$item = New-Object psobject -Property @{
Progress = $result
}
$q.Enqueue( $item )
}
}
It 'populate the input array' {
foreach ( $result in $results )
{
$item = [ConfigStep]::new()
$item.Verb = 'Test'
$item.Phase = 'Pretest'
$a.Add( $item )
}
foreach ( $result in $results )
{
'Test','Set' |
% {
$item = [ConfigStep]::new()
$item.Verb = $_
$item.Phase = 'Configure'
$a.Add( $item )
}
}
}
It "returns $returnValue" {
$r = $a | Test-ConfigStep
$r | Should be $returnValue
}
It 'correctly invokes commands' {
Assert-MockCalled Invoke-ConfigStep $invokations -Exactly
}
}
}
}
}
51 changes: 51 additions & 0 deletions Functions/testConfigStep.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function Test-ConfigStep
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 1)]
[ConfigStep]
$Step
)
begin
{
# initialize the flag
$allComplete = $true
}
process
{
# don't invoke any more steps once one has failed
if ( -not $allComplete )
{
return
}

# don't invoke any steps that are not tests
if ( $Step.Verb -ne 'Test' )
{
return
}

# don't invoke any steps that are not pretests
if ( $Step.Phase -ne 'Pretest' )
{
return
}

# invoke this step
$result = Invoke-ConfigStep $Step

# update the flag
if ( $result.Progress -ne 'Complete' )
{
$allComplete = $false
}
}
end
{
# return the value of the flag
return $allComplete
}
}
43 changes: 43 additions & 0 deletions Functions/testConfigStepPublic.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Import-Module ZeroDsc -Force
Import-Module PSDesiredStateConfiguration

Describe 'Test Environment' {
It 'add the test stubs to PSModulePath' {
. "$($PSCommandPath | Split-Path -Parent)\..\Add-StubsToModulePath.ps1"
}
It 'reset the test stub' {
$instructions = ConfigInstructions ConfigName {
Get-DscResource TestStub ZeroDsc | Import-DscResource

TestStub a @{ Key = 'a'; Mode = 'reset' }
TestStub b @{ Key = 'b'; Mode = 'reset' }
}
$instructions | Invoke-ConfigStep
}
}

Describe 'Test-ConfigStep Public API - Pipeline' {
$h = @{}
$document = {
Get-DscResource TestStub ZeroDsc | Import-DscResource

TestStub a @{ Key = 'a'}
TestStub b @{ Key = 'b'}
}
It 'create instructions' {
$h.Instructions = ConfigInstructions Name $document
$h.Instructions.Count | Should be 1
$h.Instructions.GetType() | Should be 'ConfigInstructions'
}
It 'returns false' {
$r = $h.Instructions | Test-ConfigStep
$r | Should be $false
}
It 'apply configuration' {
$h.Instructions | Invoke-ConfigStep
}
It 'returns true' {
$r = $h.Instructions | Test-ConfigStep
$r | Should be $true
}
}
2 changes: 1 addition & 1 deletion ZeroDSC.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ModuleToProcess = 'ZeroDsc.psm1'

# Version number of this module.
ModuleVersion = '0.1.1'
ModuleVersion = '0.2.0'

# ID used to uniquely identify this module
GUID = '64410c3c-434f-4ce7-b9c2-3a056f0a1831'
Expand Down
1 change: 1 addition & 0 deletions ZeroDSC.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Export-ModuleMember -Function @(
'Import-DscResource'
'ConfigInstructions'
'Invoke-ConfigStep'
'Test-ConfigStep'

'New-ResourceInvoker'
'Invoke-ResourceCommand'
Expand Down

0 comments on commit ccde9df

Please sign in to comment.