Skip to content

Commit

Permalink
Fix #136: Add -UseBasicParsing switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaydon committed Oct 23, 2020
1 parent 1a962dd commit 54d7b51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion functions/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ function CallRestUri {
if ($null -eq $params.TimeoutSec) {
$paramInvokeRestMethod.TimeoutSec = 300
}
$result = Invoke-WebRequest @paramInvokeRestMethod @params
$result = Invoke-WebRequest @paramInvokeRestMethod @params -UseBasicParsing
if ($result.Headers -and $result.Headers['Content-Type'] -like 'application/json;*') {
$result = $result.Content | ConvertFrom-Json
}
}
else {
$result = Invoke-RestMethod @paramInvokeRestMethod @params
Expand Down
14 changes: 11 additions & 3 deletions tests/core.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ Import-Module (Resolve-Path "$PSScriptRoot\..\Qlik-Cli.psd1").Path

Describe 'CallRestUri' {
InModuleScope Qlik-Cli {
Context 'when uploading or downloading files' {
Describe 'when uploading or downloading files' {
BeforeAll {
Mock Invoke-WebRequest -Verifiable { }
Mock Invoke-WebRequest -Verifiable { return $UseBasicParsing }
Mock Invoke-RestMethod { throw 'Invoke-RestMethod should not be used for file transfers' }
$script:prefix = 'https://localhost'
$script:api_params = @{ }
$script:rawOutput = $true
}

it 'should use Invoke-WebRequest' {
It 'should use Invoke-WebRequest' {
CallRestUri GET /qrs/download/scriptlog @{ OutFile = 'TestDrive:\script.log' }

Assert-VerifiableMock
}

It 'should use basic parsing' {
$result = CallRestUri GET /qrs/app/upload @{ InFile = 'TestDrive:\app.qvf' }

$result | Should -BeTrue

Assert-VerifiableMock
}
}
}
}

0 comments on commit 54d7b51

Please sign in to comment.