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' |
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
Context 'Virtual Disk exists and should but has a different Description' { | |
Mock Get-iSCSIVirtualDisk -MockWith { return @($MockVirtualDisk) } | |
Mock New-iSCSIVirtualDisk | |
Mock Set-iSCSIVirtualDisk | |
Mock Remove-iSCSIVirtualDisk | |
It 'should not throw error' { | |
{ | |
$Splat = $TestVirtualDisk.Clone() |
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
# Create the Mock Objects that will be used for running tests | |
$TestVirtualDisk = [PSObject]@{ | |
Path = Join-Path -Path $ENV:Temp -ChildPath 'TestiSCSIVirtualDisk.vhdx' | |
Ensure = 'Present' | |
DiskType = 'Differencing' | |
SizeBytes = 100MB | |
Description = 'Unit Test iSCSI Virtual Disk' | |
BlockSizeBytes = 2MB | |
PhysicalSectorSizeBytes = 4096 | |
LogicalSectorSizeBytes = 512 |
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
Context 'Virtual Disk does not exist but should' { | |
Mock Get-iSCSIVirtualDisk | |
Mock New-iSCSIVirtualDisk | |
Mock Set-iSCSIVirtualDisk | |
Mock Remove-iSCSIVirtualDisk | |
It 'should not throw error' { | |
{ | |
$Splat = $TestVirtualDisk.Clone() |
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
Context 'Virtual Disk exists but should not' { | |
Mock Get-iSCSIVirtualDisk -MockWith { return @($MockVirtualDisk) } | |
Mock New-iSCSIVirtualDisk | |
Mock Set-iSCSIVirtualDisk | |
Mock Remove-iSCSIVirtualDisk | |
It 'should not throw error' { | |
{ | |
$Splat = $TestVirtualDisk.Clone() |
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
Context 'Virtual Disk does not exist and should not' { | |
Mock Get-iSCSIVirtualDisk | |
Mock New-iSCSIVirtualDisk | |
Mock Set-iSCSIVirtualDisk | |
Mock Remove-iSCSIVirtualDisk | |
It 'should not throw error' { | |
{ | |
$Splat = $TestVirtualDisk.Clone() |
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
Context 'Virtual Disk exists and should but has a different Description' { | |
Mock Get-iSCSIVirtualDisk -MockWith { return @($MockVirtualDisk) } | |
It 'should return false' { | |
{ | |
$Splat = $TestVirtualDisk.Clone() | |
$Splat.Description = 'Different' | |
Test-TargetResource @Splat | Should Be $False | |
} | Should Not Throw |
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
Context 'Virtual Disk does not exist but should' { | |
Mock Get-iSCSIVirtualDisk | |
It 'should return false' { | |
$Splat = $TestVirtualDisk.Clone() | |
Test-TargetResource @Splat | Should Be $False | |
} | |
It 'should call expected Mocks' { |
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
Function Get-VirtualDisk { | |
param | |
( | |
[parameter(Mandatory = $true)] | |
[System.String] | |
$Path | |
) | |
try | |
{ | |
$VirtualDisk = Get-iSCSIVirtualDisk ` |
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-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 |