Skip to content

Commit

Permalink
Fix tests to work as expected under Linux (PowerShell#3474)
Browse files Browse the repository at this point in the history
- Removed the -TimeoutSec option and modified the expected Error to be consistent across platforms.
- Changed the port of the phony proxy to 9 which is reserved for the Discard Protocol. So even if the system is listening, it's supposed to discard that TCP request (UDP may use it for Wake-on-Lan, but doesn't affect this).
  • Loading branch information
TheFlyingCorpse authored and daxian-dbw committed Apr 3, 2017
1 parent f76b2fc commit 42f2e3c
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
}

$testCase = @(
@{ proxy_address = "http://localhost:8080"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://localhost:8080"; name = 'https_proxy'; protocol = 'https' }
@{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' }
)

It "Validate Invoke-WebRequest error with -Proxy option set - '<name>'" -TestCases $testCase {
Expand Down Expand Up @@ -629,17 +629,17 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
}

$testCase = @(
@{ proxy_address = "http://localhost:8080"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://localhost:8080"; name = 'https_proxy'; protocol = 'https' }
@{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' }
@{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' }
)

It "Validate Invoke-RestMethod error with -Proxy option - '<name>'" -TestCases $testCase {
param($proxy_address, $name, $protocol)

$command = "Invoke-RestMethod -Uri '${protocol}://httpbin.org/' -Proxy '${proxy_address}' -TimeoutSec 2"
$command = "Invoke-RestMethod -Uri '${protocol}://httpbin.org/' -Proxy '${proxy_address}'"

$result = ExecuteWebCommand -command $command
$result.Error.FullyQualifiedErrorId | Should Be "System.Threading.Tasks.TaskCanceledException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
$result.Error.FullyQualifiedErrorId | Should Be "WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"
}

It "Validate Invoke-RestMethod error with environment proxy set - '<name>'" -TestCases $testCase {
Expand Down

0 comments on commit 42f2e3c

Please sign in to comment.