Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Last active December 19, 2015 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlagueHO/80684b9dae6d655fcdf8 to your computer and use it in GitHub Desktop.
Save PlagueHO/80684b9dae6d655fcdf8 to your computer and use it in GitHub Desktop.
Example DSC Resource Unit Tests for Get-TargetResource function
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