diff --git a/Pester/Functions/Get-VMCHost.tests.ps1 b/Pester/Functions/Get-VMCHost.tests.ps1 index 40bde0c..921b2a0 100644 --- a/Pester/Functions/Get-VMCHost.tests.ps1 +++ b/Pester/Functions/Get-VMCHost.tests.ps1 @@ -54,7 +54,7 @@ inModuleScope VMware.VMC { } # Testing a single SDDC response It "gets the task details via list method and returns the properties" { - $(Get-VMCVMHost -Org $OrgId).esx_id | Should -be "Mocked_esx_id"#$esx_id + $(Get-VMCVMHost -Org $OrgId).esx_id | Should -be $esx_id $(Get-VMCVMHost -Org $OrgId).name | Should -be $VMHost_name $(Get-VMCVMHost -Org $OrgId).hostname | Should -be $VMhostName $(Get-VMCVMHost -Org $OrgId).esx_state | Should -be $esx_state diff --git a/Pester/Functions/Get-VMCSDDCVersion.tests.ps1 b/Pester/Functions/Get-VMCSDDCVersion.tests.ps1 new file mode 100644 index 0000000..52da5ee --- /dev/null +++ b/Pester/Functions/Get-VMCSDDCVersion.tests.ps1 @@ -0,0 +1,75 @@ +#Requires -Modules Pester, VMware.VMC +Import-Module -Name VMware.VimAutomation.Cis.Core + +inModuleScope VMware.VMC { + $functionName = "Get-VMCSDDCVersion" + Describe "$functionName" -Tag 'Unit' { + . "$PSScriptRoot/Shared.ps1" + + $global:DefaultVMCServers = $true + + $Service = "com.vmware.vmc.orgs.sddcs" + $OrgId = "Mocked OrgID" + $SddcName = "MockedSDDCName" + $version = "MockedVersion" + + $orgs = @( + [PSCustomObject]@{ + "Id" = $OrgId + "Org_Id" = $OrgId + }) + + $MockedServiceObj = [PSCustomObject]{} + + $ServicesObject = @([PSCustomObject]@{ + "resource_config" = @{ + sddc_manifest = [PSCustomObject]@{ + version = $version + } + } + }) + + Mock -CommandName Get-VMCOrg -MockWith { $orgs } + + Mock -CommandName Get-VMCService -MockWith { $MockedServiceObj } + + $MockedServiceObj | Add-Member -MemberType ScriptMethod -Name "list" -Value { $ServicesObject } + + Mock -CommandName Write-Error -MockWith {} + + Context "Sanity checking" { + $command = Get-Command -Name $functionName + + defParam $command 'Org' + defParam $command 'Name' + } + + Context "Behavior testing" { + # Testing single Org with optional SDDC parameter + It "calls Get-VMCSDDCVersion with the Org name supplied" { + { Get-VMCSDDCVersion -Org $OrgId -Name $SddcName} | Should Not Throw + Assert-MockCalled -CommandName Get-VMCOrg -Times 1 -Scope It -ParameterFilter { $Name -eq $OrgId } + } + It "calls get-service to com.vmware.vmc.orgs.sddcs" { + { Get-VMCSDDC -Org $OrgId } | Should Not Throw + Assert-MockCalled -CommandName Get-VMCService -Times 1 -Scope It -ParameterFilter { $name -eq $Service } + } + # Testing a single SDDC response + It "gets the task details via list method and returns the properties" { + $(Get-VMCSDDCVersion -Org $OrgId).version | Should -be $version + } + # Testing the multiple SDDC response + It "gets the task details of the Org supplied and returns the properties" { + Mock -CommandName Get-VMCOrg -MockWith { @($orgs, $orgs) } + + $(Get-VMCSDDCVersion -Org $OrgId)[0].version | Should -be $version + $(Get-VMCSDDCVersion -Org $OrgId)[1].version | Should -be $version + } + It "writes an error if not connected" { + $global:DefaultVMCServers = $false + { Get-VMCSDDCVersion -Org $OrgId } | Should Not Throw + Assert-MockCalled -CommandName Write-Error -Times 1 -Scope It -ParameterFilter { $org -eq $Org -and $Sddc -eq $Sddc } + } + } + } +} \ No newline at end of file