Last active
December 19, 2015 03:53
-
-
Save PlagueHO/80684b9dae6d655fcdf8 to your computer and use it in GitHub Desktop.
Example DSC Resource Unit Tests for Get-TargetResource function
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
Describe "$($Global:DSCResourceName)\Get-TargetResource" { | |
Context 'Virtual Disk does not exist' { | |
Mock Get-iSCSIVirtualDisk | |
It 'should return absent Virtual Disk' { | |
$Result = Get-TargetResource ` | |
-Path $TestVirtualDisk.Path | |
$Result.Ensure | Should Be 'Absent' | |
} | |
It 'should call the expected mocks' { | |
Assert-MockCalled -commandName Get-iSCSIVirtualDisk -Exactly 1 | |
} | |
} | |
Context 'Virtual Disk does exist' { | |
Mock Get-iSCSIVirtualDisk -MockWith { return @($TestVirtualDisk) } | |
It 'should return correct Virtual Disk' { | |
$Result = Get-TargetResource ` | |
-Path $TestVirtualDisk.Path | |
$Result.Ensure | Should Be 'Present' | |
$Result.Path | Should Be $TestVirtualDisk.Path | |
$Result.DiskType | Should Be $TestVirtualDisk.DiskType | |
$Result.SizeBytes | Should Be $TestVirtualDisk.SizeBytes | |
$Result.Description | Should Be $TestVirtualDisk.Description | |
$Result.PhysicalSectorSizeBytes | Should Be $TestVirtualDisk.PhysicalSectorSizeBytes | |
$Result.LogicalSectorSizeBytes | Should Be $TestVirtualDisk.LogicalSectorSizeBytes | |
} | |
It 'should call the expected mocks' { | |
Assert-MockCalled -commandName Get-iSCSIVirtualDisk -Exactly 1 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment