-
-
Save justinyoo/f998590e6ba3f3c6f633180c200c9b59 to your computer and use it in GitHub Desktop.
Testing Serverless Applications - Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[string] [Parameter(Mandatory=$true)] $OkUri, | |
[string] [Parameter(Mandatory=$true)] $NotFoundUri, | |
[string] [Parameter(Mandatory=$true)] $ErrorUri | |
) | |
$exitCode = 0 | |
$result = Invoke-WebRequest -Method Post -Uri $OkUri | |
if ($result.StatusCode -ne 200) | |
{ | |
Write-Host "OK test failed" | |
$exitCode++ | |
} | |
try | |
{ | |
$result = Invoke-WebRequest -Method Post -Uri $NotFoundUri | |
if ($result.StatusCode -ne 404) | |
{ | |
Write-Host "Not Found test failed" | |
$exitCode++ | |
} | |
} | |
catch | |
{ | |
$result = ([System.Net.WebException]$_.Exception).Response | |
if ([int]$result.StatusCode -ne 404) | |
{ | |
Write-Host "Not Found test failed" | |
$exitCode++ | |
} | |
} | |
try | |
{ | |
$result = Invoke-WebRequest -Method Post -Uri $ErrorUri | |
if ($result.StatusCode -lt 400) | |
{ | |
Write-Host "Error test failed" | |
$exitCode++ | |
} | |
} | |
catch | |
{ | |
$result = ([System.Net.WebException]$_.Exception).Response | |
if ([int]$result.StatusCode -lt 400) | |
{ | |
Write-Host "Error test failed" | |
$exitCode++ | |
} | |
} | |
if ($exitCode -gt 0) | |
{ | |
$host.SetShouldExit($exitCode) | |
} | |
Write-Host "All tests passed" | |
Remove-Variable result | |
Remove-Variable exitCode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment