Added new tests for get default creds
Added test for not connected route in functions to increase coverage.
This commit is contained in:
@@ -30,6 +30,8 @@ inModuleScope VMware.VMC {
|
||||
|
||||
Mock Connect-CisServer {}
|
||||
|
||||
Mock Write-Error
|
||||
|
||||
Context "Sanity checking" {
|
||||
$command = Get-Command -Name $functionName
|
||||
|
||||
@@ -57,6 +59,11 @@ inModuleScope VMware.VMC {
|
||||
-and $User -eq $cloud_username `
|
||||
-and $Password -eq $Mockedcreds.password }
|
||||
}
|
||||
It "gets writes an error if not connected" {
|
||||
$global:DefaultVMCServers = $false
|
||||
{ Connect-VMCVIServer -org $Org -Sddc $Sddc } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Write-Error -Times 1 -Scope It -ParameterFilter { $org -eq $Org -and $Sddc -eq $Sddc }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ inModuleScope VMware.VMC {
|
||||
|
||||
Mock -CommandName Get-VMCService -MockWith { $object }
|
||||
|
||||
Mock -CommandName Write-Error -MockWith {}
|
||||
|
||||
Context "Sanity checking" {
|
||||
$command = Get-Command -Name $functionName
|
||||
|
||||
@@ -46,11 +48,11 @@ inModuleScope VMware.VMC {
|
||||
It "gets the orgs via list method and returns the properties" {
|
||||
$object = [PSCustomObject]@{}
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedList }
|
||||
$(Get-VMCOrg -name $OrgName).display_name | Should -be $display_name
|
||||
$(Get-VMCOrg -name $OrgName).name | Should -be $OrgName
|
||||
$(Get-VMCOrg -name $OrgName).user_name | Should -be $user_name
|
||||
$(Get-VMCOrg -name $OrgName).created | Should -be $created
|
||||
$(Get-VMCOrg -name $OrgName).id | Should -be $id
|
||||
$(Get-VMCOrg).display_name | Should -be $display_name
|
||||
$(Get-VMCOrg).name | Should -be $OrgName
|
||||
$(Get-VMCOrg).user_name | Should -be $user_name
|
||||
$(Get-VMCOrg).created | Should -be $created
|
||||
$(Get-VMCOrg).id | Should -be $id
|
||||
}
|
||||
# Testing the multiple SDDC response
|
||||
It "calls the Connect-CisServer" {
|
||||
@@ -70,6 +72,11 @@ inModuleScope VMware.VMC {
|
||||
$(Get-VMCOrg -name $OrgName)[1].created | Should -be $created
|
||||
$(Get-VMCOrg -name $OrgName)[1].id | Should -be $id
|
||||
}
|
||||
It "gets writes an error if not connected" {
|
||||
$global:DefaultVMCServers = $false
|
||||
{ Get-VMCOrg -name $OrgName } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Write-Error -Times 1 -Scope It -ParameterFilter { $org -eq $Org -and $Sddc -eq $Sddc }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
98
Pester/Functions/Get-VMCSDDCDefaultCredential.tests.ps1
Normal file
98
Pester/Functions/Get-VMCSDDCDefaultCredential.tests.ps1
Normal file
@@ -0,0 +1,98 @@
|
||||
#Requires -Modules Pester, VMware.VMC
|
||||
Import-Module -Name VMware.VimAutomation.Cis.Core
|
||||
|
||||
inModuleScope VMware.VMC {
|
||||
$functionName = "Get-VMCSDDCDefaultCredential"
|
||||
Describe "$functionName" -Tag 'Unit' {
|
||||
. "$PSScriptRoot/Shared.ps1"
|
||||
|
||||
$global:DefaultVMCServers = $true
|
||||
|
||||
$OrgId = "Mocked OrgID"
|
||||
$SddcName = "MockedSDDCName"
|
||||
$vc_url = "Mockedvc_url"
|
||||
$vc_management_ip = "MockedVCmanage_ip"
|
||||
$vc_public_ip = "MockedVCpublic_ip"
|
||||
$cloud_username = "MockedCloudUser"
|
||||
$cloud_password = "MockedCloudPass"
|
||||
|
||||
$MockedList = [PSCustomObject]@{
|
||||
"vc_url" = $vc_url
|
||||
"vc_management_ip" = $vc_management_ip
|
||||
"vc_public_ip" = $vc_public_ip
|
||||
"cloud_username" = $cloud_username
|
||||
"cloud_password" = $cloud_password
|
||||
}
|
||||
$MockedList2 = [PSCustomObject]@{
|
||||
"vc_url" = $vc_url
|
||||
"vc_management_ip" = $vc_management_ip
|
||||
"vc_public_ip" = $vc_public_ip
|
||||
"cloud_username" = $cloud_username
|
||||
"cloud_password" = $cloud_password
|
||||
}
|
||||
|
||||
$object = [PSCustomObject]@{
|
||||
"resource_config" = @($MockedList)
|
||||
}
|
||||
|
||||
$MockedArray = @{
|
||||
"resource_config" = @($MockedList, $MockedList2)
|
||||
}
|
||||
|
||||
Mock -CommandName Get-VMCSDDC -MockWith { $object }
|
||||
|
||||
Mock -CommandName Write-Error -MockWith {}
|
||||
|
||||
Mock -CommandName Select-Object { $MockedList }
|
||||
|
||||
Context "Sanity checking" {
|
||||
$command = Get-Command -Name $functionName
|
||||
|
||||
defParam $command 'Org'
|
||||
defParam $command 'Sddc'
|
||||
}
|
||||
|
||||
Context "Behavior testing" {
|
||||
# Testing single Org with optional SDDC parameter
|
||||
It "calls Get-VMCSDDC with the Org name supplied" {
|
||||
{ Get-VMCSDDCDefaultCredential -Org $OrgId -sddc $SddcName} | Should Not Throw
|
||||
Assert-MockCalled -CommandName Get-VMCSDDC -Times 1 -Scope It -ParameterFilter { $Org -eq $OrgId -and $name -eq $SddcName }
|
||||
}
|
||||
# Testing single Org without SDDC parameter.
|
||||
It "calls get-VMCSDDC without SDDC name supplied" {
|
||||
{ Get-VMCSDDCDefaultCredential -Org $OrgId } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Get-VMCSDDC -Times 1 -Scope It -ParameterFilter { $org -eq $OrgId }
|
||||
}
|
||||
# Testing a single SDDC response
|
||||
It "gets the task details via list method and returns the properties" {
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId).vc_url | Should -be $vc_url
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId).vc_management_ip | Should -be $vc_management_ip
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId).vc_public_ip | Should -be $vc_public_ip
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId).cloud_username | Should -be $cloud_username
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId).cloud_password | Should -be $cloud_password
|
||||
Assert-MockCalled -CommandName Select-Object -Times 1 -Scope It
|
||||
}
|
||||
# Testing the multiple SDDC response
|
||||
It "gets the task details of the Org supplied and returns the properties" {
|
||||
Mock -CommandName Get-VMCSDDC -MockWith { $MockedArray }
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[0].vc_url | Should -be $vc_url
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[0].vc_management_ip | Should -be $vc_management_ip
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[0].vc_public_ip | Should -be $vc_public_ip
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[0].cloud_username | Should -be $cloud_username
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[0].cloud_password | Should -be $cloud_password
|
||||
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[1].vc_url | Should -be $vc_url
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[1].vc_management_ip | Should -be $vc_management_ip
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[1].vc_public_ip | Should -be $vc_public_ip
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[1].cloud_username | Should -be $cloud_username
|
||||
$(Get-VMCSDDCDefaultCredential -Org $OrgId)[1].cloud_password | Should -be $cloud_password
|
||||
Assert-MockCalled -CommandName Select-Object -Times 2 -Scope It
|
||||
}
|
||||
It "writes an error if not connected" {
|
||||
$global:DefaultVMCServers = $false
|
||||
{ Get-VMCSDDCDefaultCredential -Org $OrgId } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Write-Error -Times 1 -Scope It -ParameterFilter { $org -eq $Org -and $Sddc -eq $Sddc }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ inModuleScope VMware.VMC {
|
||||
|
||||
Mock -CommandName Get-VMCOrg { $object }
|
||||
|
||||
Mock -CommandName Write-Error -MockWith {}
|
||||
|
||||
Context "Sanity checking" {
|
||||
$command = Get-Command -Name $functionName
|
||||
|
||||
@@ -77,6 +79,11 @@ inModuleScope VMware.VMC {
|
||||
$object | Add-Member -MemberType ScriptMethod -Name "list" -Value { $MockedArray }
|
||||
$(Get-VMCSDDC -Org $OrgId -name $name).name | Should -be $name
|
||||
}
|
||||
It "gets writes an error if not connected" {
|
||||
$global:DefaultVMCServers = $false
|
||||
{ Get-VMCSDDC -Org $OrgId } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Write-Error -Times 1 -Scope It -ParameterFilter { $org -eq $Org -and $Sddc -eq $Sddc }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ inModuleScope VMware.VMC {
|
||||
|
||||
Mock -CommandName Get-VMCOrg { $object }
|
||||
|
||||
Mock -CommandName Write-Error -MockWith {}
|
||||
|
||||
Context "Sanity checking" {
|
||||
$command = Get-Command -Name $functionName
|
||||
|
||||
@@ -75,6 +77,11 @@ inModuleScope VMware.VMC {
|
||||
$(Get-VMCTask -Org $OrgId)[0].name | Should -be $name
|
||||
$(Get-VMCTask -Org $OrgId)[1].name | Should -be $Notname
|
||||
}
|
||||
It "gets writes an error if not connected" {
|
||||
$global:DefaultVMCServers = $false
|
||||
{ Get-VMCTask -Org $OrgId } | Should Not Throw
|
||||
Assert-MockCalled -CommandName Write-Error -Times 1 -Scope It -ParameterFilter { $org -eq $Org -and $Sddc -eq $Sddc }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user