48 lines
2.0 KiB
PowerShell
48 lines
2.0 KiB
PowerShell
|
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
||
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
|
||
|
$functionPath = Join-Path -Path $here -ChildPath $sut
|
||
|
Write-Host "Overriding SUT: $functionPath"
|
||
|
Import-Module $functionPath -Force
|
||
|
$moduleForMock = ""
|
||
|
$currentErrorActionPreference = $ErrorActionPreference
|
||
|
$ErrorActionPreference = "stop"
|
||
|
|
||
|
Describe "Invoke-ProgetRequest" {
|
||
|
Mock Write-Host
|
||
|
Mock Get-LogLeadName
|
||
|
Mock Write-Warning
|
||
|
Mock Invoke-WebRequest
|
||
|
|
||
|
$URI = "fakeURI"
|
||
|
$Headers = @{boo = "fake Header" }
|
||
|
|
||
|
Context "Assert mocks are called" {
|
||
|
Mock Invoke-CommandWithRetry { return @{StatusCode = "200" } }
|
||
|
It "Assert ICWR mock is called " {
|
||
|
mock Invoke-CommandWithRetry { return $null }
|
||
|
Invoke-ProgetRequest -URI $URI -Headers $Headers
|
||
|
Assert-MockCalled Invoke-CommandWithRetry
|
||
|
}
|
||
|
}
|
||
|
Context "Throw Checking" {
|
||
|
Mock Invoke-CommandWithRetry { throw [System.Net.WebException] "The operation has timed out." }
|
||
|
It "Throws when timing out" {
|
||
|
{ Invoke-ProgetRequest -URI $URI -Headers $Headers -ErrorAction Stop} | Should -Throw
|
||
|
}
|
||
|
It "500 response code should throw" {
|
||
|
Mock Invoke-CommandWithRetry { return @{StatusCode = "500" } }
|
||
|
{ Invoke-ProgetRequest -URI $URI -Headers $Headers -ErrorAction Stop} | Should -Not -Throw
|
||
|
}
|
||
|
It "200 response code should not throw" {
|
||
|
Mock Invoke-CommandWithRetry { return @{StatusCode = "200" } }
|
||
|
{ Invoke-ProgetRequest -URI $URI -Headers $Headers -ErrorAction Stop} | Should -Not -Throw
|
||
|
}
|
||
|
It "300 response code should throw" {
|
||
|
Mock Invoke-CommandWithRetry { return @{StatusCode = "300" } }
|
||
|
{ Invoke-ProgetRequest -URI $URI -Headers $Headers -ErrorAction Stop} | Should -Not -Throw
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$ErrorActionPreference = $currentErrorActionPreference
|