Created tests for get VMC Task
Trimed out excess fom get SDDC parameters in the object.
This commit is contained in:
@@ -7,33 +7,20 @@ Describe "$functionName" -Tag 'Unit' {
|
||||
|
||||
$global:DefaultVMCServers = $true
|
||||
|
||||
$display_name = "MockedDisplayName"
|
||||
$user_name = "MockedUserName"
|
||||
$OrgName = "MockedOrgName"
|
||||
$created = "MockedDate"
|
||||
$OrgId = "Mocked OrgID"
|
||||
$name = "MockedSDDCName"
|
||||
$Notname = "NotTheName"
|
||||
$id = "MockedId"
|
||||
$Service = "com.vmware.vmc.orgs.sddcs"
|
||||
|
||||
$MockedList = [PSCustomObject]@{
|
||||
"display_name" = $display_name
|
||||
"name" = $name
|
||||
"created" = $created
|
||||
"user_name" = $user_name
|
||||
"id" = $id
|
||||
}
|
||||
$MockedList2 = [PSCustomObject]@{
|
||||
"display_name" = $display_name
|
||||
"name" = $Notname
|
||||
"created" = $created
|
||||
"user_name" = $user_name
|
||||
"id" = $id
|
||||
}
|
||||
|
||||
$object = @(
|
||||
@{"Id" = $Id}
|
||||
@{"Id" = 1}
|
||||
)
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList }
|
||||
|
||||
@@ -81,7 +68,7 @@ Describe "$functionName" -Tag 'Unit' {
|
||||
It "gets the SDDC details via list method and returns the properties" {
|
||||
$object = [PSCustomObject]@{}
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList }
|
||||
$(Get-VMCSDDC -Org $OrgId).display_name | Should -be $display_name
|
||||
$(Get-VMCSDDC -Org $OrgId).name | Should -be $name
|
||||
}
|
||||
# Testing the multiple SDDC response
|
||||
It "gets the SDDC details of the SDDC supplied and returns the properties" {
|
||||
|
||||
78
Pester/Functions/Get-VmcTask.tests.ps1
Normal file
78
Pester/Functions/Get-VmcTask.tests.ps1
Normal file
@@ -0,0 +1,78 @@
|
||||
#Requires -Modules Pester, VMware.VMC
|
||||
$functionName = $MyInvocation.MyCommand.Name.TrimEnd(".Tests.ps1")
|
||||
Import-Module -Name VMware.VimAutomation.Cis.Core
|
||||
|
||||
Describe "$functionName" -Tag 'Unit' {
|
||||
. "$PSScriptRoot/Shared.ps1"
|
||||
|
||||
$global:DefaultVMCServers = $true
|
||||
|
||||
$OrgId = "Mocked OrgID"
|
||||
$name = "MockedSDDCName"
|
||||
$Notname = "NotTheName"
|
||||
$id = "MockedId"
|
||||
$Service = "com.vmware.vmc.orgs.tasks"
|
||||
|
||||
$MockedList = [PSCustomObject]@{
|
||||
"name" = $name
|
||||
}
|
||||
$MockedList2 = [PSCustomObject]@{
|
||||
"name" = $Notname
|
||||
}
|
||||
|
||||
$object = @(
|
||||
@{"Id" = $Id}
|
||||
)
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList }
|
||||
|
||||
$MockedArray = @($MockedList, $MockedList2)
|
||||
|
||||
Mock -CommandName Get-VMCService -MockWith { $object }
|
||||
|
||||
Mock -CommandName Get-VMCOrg { $object }
|
||||
|
||||
Context "Sanity checking" {
|
||||
$command = Get-Command -Name $functionName
|
||||
|
||||
defParam $command 'Org'
|
||||
}
|
||||
|
||||
Context "Behavior testing" {
|
||||
|
||||
It "calls Get-VMCOrg with the Org name supplied" {
|
||||
{ Get-VMCTask -Org $name} | Should Not Throw
|
||||
Assert-MockCalled -CommandName Get-VMCOrg -Times 1 -Scope It -ParameterFilter { $name -eq $name }
|
||||
}
|
||||
|
||||
# Testing with single "Org" so assert call twice.
|
||||
It "calls get-service to com.vmware.vmc.orgs.tasks" {
|
||||
{ Get-VMCTask -Org $OrgId } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Get-VMCService -Times 1 -Scope It -ParameterFilter { $name -eq $Service }
|
||||
}
|
||||
|
||||
# Testing with two "Orgs" so assert call twice.
|
||||
It "calls get-service to com.vmware.vmc.orgs.tasks" {
|
||||
$object = @(
|
||||
@{"Id" = 1}
|
||||
@{"Id" = 2}
|
||||
)
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedArray }
|
||||
{ Get-VMCTask -Org $OrgId } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Get-VMCService -Times 2 -Scope It -ParameterFilter { $name -eq $Service }
|
||||
}
|
||||
|
||||
# Testing a single SDDC response
|
||||
It "gets the task details via list method and returns the properties" {
|
||||
$object = [PSCustomObject]@{}
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList }
|
||||
$(Get-VMCTask -Org $OrgId).name | Should -be $name
|
||||
}
|
||||
# Testing the multiple SDDC response
|
||||
It "gets the task details of the SDDC supplied and returns the properties" {
|
||||
$object = @{}
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedArray }
|
||||
$(Get-VMCTask -Org $OrgId)[0].name | Should -be $name
|
||||
$(Get-VMCTask -Org $OrgId)[1].name | Should -be $Notname
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user