Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Created December 23, 2015 05:49
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/593cdfc77c63d5fe19b4 to your computer and use it in GitHub Desktop.
Save PlagueHO/593cdfc77c63d5fe19b4 to your computer and use it in GitHub Desktop.
Example DSC Unit Tests for Get-VirtualDisk function
Describe "$($Global:DSCResourceName)\Get-VirtualDisk" {
Context 'Virtual Disk does not exist' {
Mock Get-iSCSIVirtualDisk
It 'should return null' {
$Splat = $TestVirtualDisk.Clone()
$Result = Get-VirtualDisk -Path $Splat.Path
$Result | Should Be $null
}
It 'should call expected Mocks' {
Assert-MockCalled -commandName Get-iSCSIVirtualDisk -Exactly 1
}
}
Context 'Virtual Disk does exist' {
Mock Get-iSCSIVirtualDisk -MockWith { return @($MockVirtualDisk) }
It 'should return expected parameters' {
$Splat = $TestVirtualDisk.Clone()
$Result = Get-VirtualDisk -Path $Splat.Path
$Result.Path | Should Be $MockVirtualDisk.Path
$Result.DiskType | Should Be $MockVirtualDisk.DiskType
$Result.Size | Should Be $MockVirtualDisk.Size
$Result.Description | Should Be $MockVirtualDisk.Description
$Result.ParentPath | Should Be $MockVirtualDisk.ParentPath
}
It 'should call 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