Tests/VCF.SnapshotManager.Tests.ps1
|
BeforeAll { function global:Get-AnyStackConnection { param($Server) return [PSCustomObject]@{Name='MockVC'} } function global:Invoke-AnyStackWithRetry { param($ScriptBlock) & $ScriptBlock } Import-Module "$PSScriptRoot\..\VCF.SnapshotManager.psd1" -Force } Describe "VCF.SnapshotManager Suite" { Context "Clear-AnyStackOrphanedSnapshots" { It "Should return expected object shape" { Mock Get-AnyStackConnection { return [PSCustomObject]@{Name='MockVC'} } -ModuleName "VCF.SnapshotManager" Mock Invoke-AnyStackWithRetry { param($ScriptBlock) & $ScriptBlock } -ModuleName "VCF.SnapshotManager" Mock Get-View { return @([PSCustomObject]@{Name='vm01'; MoRef=[PSCustomObject]@{Value='vm-1'}; Snapshot=$null; Guest=[PSCustomObject]@{IpAddress='192.168.1.10'}; Runtime=[PSCustomObject]@{PowerState='poweredOn'; Host=[PSCustomObject]@{Value='host-1'}}; Config=[PSCustomObject]@{Hardware=[PSCustomObject]@{NumCPU=2; MemoryMB=4096}; Modified=(Get-Date).AddDays(-30)}; Summary=[PSCustomObject]@{Storage=[PSCustomObject]@{Committed=10GB}}}) } -ModuleName "VCF.SnapshotManager" $result = Clear-AnyStackOrphanedSnapshots -Server 'mock' -ErrorAction SilentlyContinue $result | Should -Not -BeNullOrEmpty $result[0].PSTypeName | Should -Not -BeNullOrEmpty } } Context "Optimize-AnyStackSnapshots" { It "Should return expected object shape" { Mock Get-AnyStackConnection { return [PSCustomObject]@{Name='MockVC'} } -ModuleName "VCF.SnapshotManager" Mock Invoke-AnyStackWithRetry { param($ScriptBlock) & $ScriptBlock } -ModuleName "VCF.SnapshotManager" Mock Get-View { return @([PSCustomObject]@{Name='vm01'; MoRef=[PSCustomObject]@{Value='vm-1'}; Snapshot=$null; Guest=[PSCustomObject]@{IpAddress='192.168.1.10'}; Runtime=[PSCustomObject]@{PowerState='poweredOn'; Host=[PSCustomObject]@{Value='host-1'}}; Config=[PSCustomObject]@{Hardware=[PSCustomObject]@{NumCPU=2; MemoryMB=4096}; Modified=(Get-Date).AddDays(-30)}; Summary=[PSCustomObject]@{Storage=[PSCustomObject]@{Committed=10GB}}}) } -ModuleName "VCF.SnapshotManager" $result = Optimize-AnyStackSnapshots -Server 'mock' -ErrorAction SilentlyContinue $result | Should -Not -BeNullOrEmpty $result[0].PSTypeName | Should -Not -BeNullOrEmpty } } } |