Tests/AnyStack.ConfigurationAsCode.Tests.ps1
|
BeforeAll { function global:Get-AnyStackConnection { param($Server) return [PSCustomObject]@{Name='MockVC'} } function global:Invoke-AnyStackWithRetry { param($ScriptBlock) & $ScriptBlock } Import-Module "$PSScriptRoot\..\AnyStack.ConfigurationAsCode.psd1" -Force } Describe "AnyStack.ConfigurationAsCode Suite" { Context "Export-AnyStackConfiguration" { It "Should return expected object shape" { Mock Get-AnyStackConnection { return [PSCustomObject]@{Name='MockVC'} } -ModuleName "AnyStack.ConfigurationAsCode" Mock Invoke-AnyStackWithRetry { param($ScriptBlock) & $ScriptBlock } -ModuleName "AnyStack.ConfigurationAsCode" 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 "AnyStack.ConfigurationAsCode" $result = Export-AnyStackConfiguration -Server 'mock' -ErrorAction SilentlyContinue $result | Should -Not -BeNullOrEmpty $result[0].PSTypeName | Should -Not -BeNullOrEmpty } } Context "Sync-AnyStackConfiguration" { It "Should return expected object shape" { Mock Get-AnyStackConnection { return [PSCustomObject]@{Name='MockVC'} } -ModuleName "AnyStack.ConfigurationAsCode" Mock Invoke-AnyStackWithRetry { param($ScriptBlock) & $ScriptBlock } -ModuleName "AnyStack.ConfigurationAsCode" 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 "AnyStack.ConfigurationAsCode" $result = Sync-AnyStackConfiguration -Server 'mock' -ErrorAction SilentlyContinue $result | Should -Not -BeNullOrEmpty $result[0].PSTypeName | Should -Not -BeNullOrEmpty } } } |