-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from alx9r/implement-Test-ConfigStep
Implement test config step
- Loading branch information
Showing
6 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
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
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
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 | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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 | ||
} | ||
} |
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
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 | ||
} | ||
} |
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
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