Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created July 20, 2017 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/f998590e6ba3f3c6f633180c200c9b59 to your computer and use it in GitHub Desktop.
Save justinyoo/f998590e6ba3f3c6f633180c200c9b59 to your computer and use it in GitHub Desktop.
Testing Serverless Applications - Part 2
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