Skip to content

Commit

Permalink
Ignore TCP testing for Linux systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hunt committed Feb 9, 2024
1 parent 0647d4f commit 02c152e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
20 changes: 13 additions & 7 deletions src/httpunitPS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,21 @@ class TestCase {

$result.Label = '{0} ({1})' -f $result.Label, $testName

$testOutput = Test-NetConnection -ComputerName $testName -Port $testPort
if ([System.Environment]::OSVersion.Platform.ToString() -eq 'Win32NT') {
$testOutput = Test-NetConnection -ComputerName $testName -Port $testPort

if (!$testOutput.TcpTestSucceeded) {
$result.Connected = $false
$exception = [Exception]::new(("TCP connect to ({0} : {1}) failed" -f $testName, $testPort ))
$result.Result = [System.Management.Automation.ErrorRecord]::new($exception, "10", "ConnectionError", $this.URL)
}

$result.Response = $testOutput
if (!$testOutput.TcpTestSucceeded) {
$result.Connected = $false
$exception = [Exception]::new(("TCP connect to ({0} : {1}) failed" -f $testName, $testPort ))
$result.Result = [System.Management.Automation.ErrorRecord]::new($exception, "10", "ConnectionError", $this.URL)
}

$result.Response = $testOutput
} else {
$exception = [Exception]::new(("Not yet implemented on this platform" ))
$result.Result = [System.Management.Automation.ErrorRecord]::new($exception, "100", "NotImplemented", $this.URL)
}
$result.TimeTotal = (Get-Date) - $time
return $result
}
Expand Down
33 changes: 21 additions & 12 deletions test/httpunitps.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Describe 'Invoke-HttpUnit' {
It 'Should return 200 for google' {
$result = Invoke-HttpUnit -Url https://www.google.com -Code 200

$result.Label | Should -Be "https://www.google.com/"
$result.Label | Should -Match "https://www.google.com/"
$result.Result | Should -BeNullOrEmpty
$result.Connected | Should -Be $True
$result.GotCode | Should -Be $True
Expand All @@ -22,7 +22,7 @@ Describe 'Invoke-HttpUnit' {
It 'Should support string matching' {
$result = Invoke-HttpUnit -Url https://example.com/ -String 'Example Domain'

$result.Label | Should -Be "https://example.com/"
$result.Label | Should -Match "https://example.com/"
$result.Result | Should -BeNullOrEmpty
$result.Connected | Should -Be $True
$result.GotCode | Should -Be $True
Expand Down Expand Up @@ -51,15 +51,24 @@ Describe 'Invoke-HttpUnit' {
It 'Should test a TCP port' {
$result = Invoke-HttpUnit -Url tcp://example.com:443

$result.Result | Should -BeNullOrEmpty
if ($IsLinux) {
$result.Result.Exception.Message | Should -Be 'Not yet implemented on this platform'
} else {
$result.Result | Should -BeNullOrEmpty
}

$result.Connected | Should -Be $true
}

It 'Should report a failed TCP test' {
$result = Invoke-HttpUnit -Url tcp://example.com:442 -Quiet

$result.Connected | Should -Be $false
$result.Result.Exception.Message | Should -Be 'TCP connect to (example.com : 442) failed'
if ($IsLinux) {
$result.Result.Exception.Message | Should -Be 'Not yet implemented on this platform'
} else {
$result.Connected | Should -Be $false
$result.Result.Exception.Message | Should -Match 'TCP connect to \(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3} : 442\) failed'
}
}
}

Expand All @@ -70,7 +79,7 @@ Describe 'Invoke-HttpUnit' {
) {
$result = Invoke-HttpUnit -Path $config

$result.Label | Should -BeExactly "google"
$result.Label | Should -Match "google"
$result.Result | Should -BeNullOrEmpty
$result.Connected | Should -Be $True
$result.GotCode | Should -Be $True
Expand All @@ -86,7 +95,7 @@ Describe 'Invoke-HttpUnit' {

$result.Count | Should -Be 2
foreach ($item in $result) {
$item.Label | Should -BeExactly "google"
$item.Label | Should -Match "google"
$item.Result | Should -BeNullOrEmpty
$item.Connected | Should -Be $True
$item.GotCode | Should -Be $True
Expand All @@ -101,7 +110,7 @@ Describe 'Invoke-HttpUnit' {
It 'Should filter by tag' {
$result = Invoke-HttpUnit -Path "$PSScriptRoot/testconfig2.yaml" -Tag Run

$result.Label | Should -BeExactly "good"
$result.Label | Should -Match "good"
$result.Result | Should -BeNullOrEmpty
$result.Connected | Should -Be $True
$result.GotCode | Should -Be $True
Expand All @@ -116,7 +125,7 @@ Describe 'Invoke-HttpUnit' {
$result = Invoke-HttpUnit -Path "$PSScriptRoot/testconfig2.yaml" -Tag run-ips

$result.Count | Should -BeGreaterThan 0
$result[0].Label | Should -BeExactly "IPs"
$result[0].Label | Should -Match "IPs"
$result[0].response.RequestMessage.RequestUri.OriginalString | Should -Not -Be 'https://*'
$result[0].response.RequestMessage.Headers.Host | Should -Be 'www.google.com'
}
Expand All @@ -129,7 +138,7 @@ Describe 'Invoke-HttpUnit' {
}
$result = $inputObject | Invoke-HttpUnit

$result.Label | Should -Be "https://www.google.com/"
$result.Label | Should -Match "https://www.google.com/"
$result.Result | Should -BeNullOrEmpty
$result.Connected | Should -Be $True
$result.GotCode | Should -Be $True
Expand All @@ -147,7 +156,7 @@ Describe 'Invoke-HttpUnit' {
$result = $inputObject | Invoke-HttpUnit

$result.Count | Should -Be 2
$result[0].Label | Should -Be "https://www.google.com/"
$result[0].Label | Should -Match "https://www.google.com/"
$result[0].Result | Should -BeNullOrEmpty
$result[0].Connected | Should -Be $True
$result[0].GotCode | Should -Be $True
Expand All @@ -157,7 +166,7 @@ Describe 'Invoke-HttpUnit' {
$result[0].InvalidCert | Should -Be $False
$result[0].TimeTotal | Should -BeGreaterThan ([timespan]::new(1))

$result[1].Label | Should -Be "https://example.com/"
$result[1].Label | Should -Match "https://example.com/"
$result[1].Result | Should -BeNullOrEmpty
$result[1].Connected | Should -Be $True
$result[1].GotCode | Should -Be $True
Expand Down

0 comments on commit 02c152e

Please sign in to comment.