From ed6024fe63c0a18c86163dfd67e0b34baa427a5e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 14 Apr 2020 16:24:45 -0400 Subject: [PATCH] Add Tests for Password Update # Conflicts: # Tests/Public/Edit-ZertoVra.Tests.ps1 --- Tests/Public/Edit-ZertoVra.Tests.ps1 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Tests/Public/Edit-ZertoVra.Tests.ps1 b/Tests/Public/Edit-ZertoVra.Tests.ps1 index 3767301..6e8de1e 100644 --- a/Tests/Public/Edit-ZertoVra.Tests.ps1 +++ b/Tests/Public/Edit-ZertoVra.Tests.ps1 @@ -8,7 +8,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Get-Content $global:here\Mocks\TaskId.txt } - Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -eq "MyVraIdentifier" } { + Mock -ModuleName ZertoApiWrapper Get-ZertoVra -ParameterFilter { $vraIdentifier -in @("MyVraIdentifier", "PasswordVraIdentifier") } { Get-Content $global:here\Mocks\GetSingleVra.json -Raw | ConvertFrom-Json } @@ -59,6 +59,13 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { $attrs.Where{ $_ -is [ValidateScript] }.Count | Should -Be 1 $attrs.Where{ $_ -is [ValidateScript] }.ScriptBlock | Should -Match '\$_ \-match \[IPAddress\]\$_' } + + It "Supports 'SupportsShouldProcess'" { + Get-Command $global:function | Should -HaveParameter WhatIf + Get-Command $global:function | Should -HaveParameter Confirm + (Get-Command $global:function).ScriptBlock | Should -Match 'SupportsShouldProcess' + (Get-Command $global:function).ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)' + } } Context "$($global:function)::Function Unit Tests" { @@ -82,16 +89,14 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Edit-ZertoVra -vraIdentifier "DhcpVraIdentifier" -groupName "MyNewGroup" | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a" } - It "Supports 'SupportsShouldProcess'" { - Get-Command $global:function | Should -HaveParameter WhatIf - Get-Command $global:function | Should -HaveParameter Confirm - (Get-Command $global:function).ScriptBlock | Should -Match 'SupportsShouldProcess' - (Get-Command $global:function).ScriptBlock | Should -Match '\$PSCmdlet\.ShouldProcess\(.+\)' + It "Runs with root password provided" { + $SecurePassword = 'NotARealPassword' | ConvertTo-SecureString -AsPlainText -Force + Edit-ZertoVra -vraIdentifier "PasswordVraIdentifier" -HostRootPassword $SecurePassword | Should -BeExactly "7e79035e-fb8c-47fe-815c-12ddd41708e6.3e4cdd0d-1064-4022-921f-6265ad6d335a" } } - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 3 - Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra -Exactly 4 + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest -Exactly 4 + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra -Exactly 5 } Remove-Variable -Name function -Scope Global