Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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