Fix tests to work as expected under Linux (#3474)

- 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).
This commit is contained in:
Rune Darrud 2017-04-03 02:31:22 +02:00 committed by Dongbo Wang
parent f76b2fcbaf
commit 42f2e3ca82

View file

@ -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 {
@ -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 {