Skip to content

Commit

Permalink
feat: Added URL fetch error handling to test script (#642)
Browse files Browse the repository at this point in the history
## Description

Handling cases where the URL is wrong or invalid. Will write a warning
and skip the check instead of throwing an exception

Depends on #613 as we should add the same to its telemetry check


| Pipeline |
| - |

|[![avm.res.key-vault.vault](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=users%2Falsehr%2FerrorHandling&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml)
|

---------

Co-authored-by: Erika Gressi <[email protected]>
  • Loading branch information
AlexanderSehr and eriqua authored Nov 17, 2023
1 parent 149cf09 commit 030b64d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,18 @@ Describe 'Module tests' -Tag 'Module' {
}
$implementedSchema = $templateFileContentBicep[$implementedSchemaStartIndex..$implementedSchemaEndIndex]

$expectedSchemaFull = (Invoke-WebRequest -Uri $expectedUdtUrl).Content -split '\n'
try {
$rawReponse = Invoke-WebRequest -Uri $expectedUdtUrl
if (($rawReponse.Headers['Content-Type'] | Out-String) -like "*text/plain*") {
$expectedSchemaFull = $rawReponse.Content -split '\n'
} else {
throw "Failed to fetch schema from [$expectedUdtUrl]. Skipping schema check"
}
} catch {
Write-Warning "Failed to fetch schema from [$expectedUdtUrl]. Skipping schema check"
return
}

$expectedSchemaStartIndex = $expectedSchemaFull.IndexOf("type $udtName = {")
$expectedSchemaEndIndex = $expectedSchemaStartIndex + 1
while ($expectedSchemaFull[$expectedSchemaEndIndex] -notmatch '^\}.*' -and $expectedSchemaEndIndex -lt $expectedSchemaFull.Length) {
Expand Down

0 comments on commit 030b64d

Please sign in to comment.