From 030b64d1b352eab912064eba9805906f5680d385 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Fri, 17 Nov 2023 12:50:59 +0100 Subject: [PATCH] feat: Added URL fetch error handling to test script (#642) ## 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 <56914614+eriqua@users.noreply.github.com> --- .../staticValidation/compliance/module.tests.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/avm/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/avm/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index d3d0d80876..e6860cb5dc 100644 --- a/avm/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/avm/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -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) {