Skip to content

Commit

Permalink
Add tests for transfer-encoding header
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaydon committed Jan 19, 2024
1 parent 52fe8fd commit 0b34ef4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/unit/core.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@ Describe 'CallRestUri' {
InModuleScope Qlik-Cli {
Describe 'when uploading or downloading files' {
BeforeAll {
Mock Invoke-WebRequest -Verifiable { return $UseBasicParsing }
Mock Invoke-WebRequest -Verifiable {
$script:webSessionContainer = @{ Headers = $Headers }
return @{
UseBasicParsing = $UseBasicParsing
TransferEncodingHeader = $Headers.ContainsKey('Transfer-Encoding')
}
}
Mock Invoke-RestMethod { throw 'Invoke-RestMethod should not be used for file transfers' }
$script:prefix = 'https://localhost'
$script:api_params = @{ }
$script:rawOutput = $true
}

BeforeEach {
$script:webSessionContainer = $null
}

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

Assert-VerifiableMock
}

It 'should use basic parsing' {
It 'should use basic parsing and transfer-encoding header for uploads' {
$result = CallRestUri GET /qrs/app/upload @{ InFile = 'TestDrive:\app.qvf' }

$result | Should -BeTrue
$result.UseBasicParsing | Should -BeTrue
$result.TransferEncodingHeader | Should -BeTrue
# Header should be present in request and removed from session after
$script:webSessionContainer.Headers.Keys | Should -Not -Contain 'Transfer-Encoding'

Assert-VerifiableMock
}
Expand Down

0 comments on commit 0b34ef4

Please sign in to comment.