73 lines
2.7 KiB
PowerShell
73 lines
2.7 KiB
PowerShell
#Requires -Modules Pester
|
|
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
|
$script:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
|
|
|
|
Describe $script:function -Tag 'Unit', 'Source', 'Built' {
|
|
BeforeAll {
|
|
$script:ScriptBlock = (Get-Command $script:function).ScriptBlock
|
|
}
|
|
|
|
Context "$($script:function)::Parameter Unit Tests" {
|
|
It "Has a parameter for the Required Credentials that is Mandatory" {
|
|
Get-Command $script:function | Should -HaveParameter credential -Mandatory -Type PSCredential
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Context "$($script:function)::Function Unit Tests" {
|
|
|
|
InModuleScope -ModuleName ZertoApiWrapper {
|
|
Mock -CommandName Invoke-ZARestRequest {
|
|
return (Get-Content "$global:here\Mocks\ZAToken.json"-Raw | ConvertFrom-Json)
|
|
}
|
|
|
|
$password = 'NotARealPassword' | ConvertTo-SecureString -AsPlainText -Force
|
|
$cred = New-Object pscredential('NotARealUser', $password)
|
|
|
|
$results = Connect-ZertoAnalytics -credential $cred
|
|
|
|
It "Creates a Script Level Hashtable Variable for the ZertoAnalytics Headers" {
|
|
$script:zaHeaders | Should -BeOfType Hashtable
|
|
}
|
|
|
|
It "the ZertoAnalytics Headers variable contains 2 items" {
|
|
$script:zaHeaders.keys | Should -HaveCount 2
|
|
}
|
|
|
|
It "the ZertoAnalytics Headers variable has an 'Accept' key" {
|
|
$script:zaHeaders.keys | Should -Contain 'Accept'
|
|
}
|
|
|
|
It "thh ZertoAnalytics headers variable 'Accept' key should be JSON" {
|
|
$script:zaHeaders['Accept'] | Should -match 'application/json'
|
|
}
|
|
|
|
It "the ZertoAnalytics Headers variable has an 'Authorization' key" {
|
|
$script:zaHeaders.keys | Should -Contain 'Authorization'
|
|
}
|
|
|
|
It "the ZertoAnalytics Headers variable 'Authorization' key should start with 'Bearer'" {
|
|
$script:zaHeaders['Authorization'] | Should -Match '^Bearer '
|
|
}
|
|
|
|
It "Creates a Script Level Variable for the LastActionTime" {
|
|
$script:zaLastActionTime | Should -BeOfType Long
|
|
}
|
|
|
|
It "LastActionTime Variable should be in the past" {
|
|
$script:zaLastActionTime | Should -BeLessThan (Get-Date).Ticks
|
|
}
|
|
|
|
It "Returns Header Information" {
|
|
$results | Should -not -BeNullOrEmpty
|
|
$results['Authorization'] | Should -MatchExactly 'Bearer N074r34l70k3n'
|
|
$results['Accept'] | Should -Match 'application/json'
|
|
}
|
|
}
|
|
|
|
Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZARestRequest -Exactly 1
|
|
}
|
|
|
|
}
|