From 9008cdd0700a7b337ca6d60442ecc7ae02308f7a Mon Sep 17 00:00:00 2001 From: Vishnu Priya Ananthu Sundaram Date: Wed, 16 Nov 2016 16:02:04 -0800 Subject: [PATCH] Refactoring Invoke-RestMethod to facilitate mocking. This closes #15 --- tools/AzureRM.BootStrapper/AzureRM.Bootstrapper.psm1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/AzureRM.BootStrapper/AzureRM.Bootstrapper.psm1 b/tools/AzureRM.BootStrapper/AzureRM.Bootstrapper.psm1 index 69d6f85fc695..da04a7bdcd08 100644 --- a/tools/AzureRM.BootStrapper/AzureRM.Bootstrapper.psm1 +++ b/tools/AzureRM.BootStrapper/AzureRM.Bootstrapper.psm1 @@ -13,13 +13,18 @@ else $script:BootStrapRepo = $existingRepos[0].Name } - function Get-ProfileCachePath { $ProfileCache = Join-Path -path $env:LOCALAPPDATA -childpath "Microsoft\AzurePowerShell\ProfileCache" return $ProfileCache } +# Make Rest-Call +function Get-RestResponse +{ + $response = Invoke-RestMethod -ea SilentlyContinue -Uri $PSProfileMapEndpoint -ErrorVariable RestError -OutFile "$ProfileCache\ProfileMap.Json" + return $RestError +} # Get-ProfileMap from Azure Endpoint function Get-AzureProfileMap @@ -30,7 +35,7 @@ function Get-AzureProfileMap New-Item -ItemType Directory -Force -Path $ProfileCache | Out-Null } - $response = Invoke-RestMethod -ea SilentlyContinue -Uri $PSProfileMapEndpoint -ErrorVariable RestError -OutFile "$ProfileCache\ProfileMap.Json" + $RestError = Get-RestResponse if ($RestError) {