Hi,
I have been using a previous version of Pester
to test a load of https APIs. Each API requires a set of headers passed into each request. Previously I was just adding these as a function before and passing the values into the pester test. but now these all fail to run and I’m not sure I understand why.
I’ve added the beforeEach{
and added my function within that script block, but it still fails.
BeforeEach{ function Get.WebRequest.Headers { [cmdletbinding()] param( $AccessKey = "##################################", $uri = "https://############identity##########/oauth2/default/v1/token", $endPoints = (Get-Content .\Pester.Test.Apis.WebRequest\Api.Endpoints.json | ConvertFrom-Json -AsHashtable) ) $Headers = @{} $Headers.Authorization = "####################################################" $headers.'Content-Type' = "#######################" $headers.Cookie = "####################################################" $Body = "##############################################"$R = Invoke-WebRequest -uri $Uri ` -Body $body ` -Headers $headers ` -Method POST $Token = $R.Content | ConvertFrom-Json $Token = "Bearer $($token.Access_Token)" }
}
Describe ‘Testing all environment endpoints’ {
Context ‘API Test against #############’{
foreach ($endpoint in $endPoints.endpoints.#########.Values){
$date = Get-Date
it “$date Testing $endpoint”{
$headers = @{}
$headers.Authorization = “$Token”
$headers.“################” = “$AccessKey”
$R = Invoke-WebRequest -Uri $endPoint-Headers $Headers
-Method GET
$R.StatusCode | should be 200
$R
}
}
}
Any help would be great.
Thanks