Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,13 @@ public class TestConnectionCommand : PSCmdlet, IDisposable
/// </summary>
protected override void BeginProcessing()
{
switch (ParameterSetName)
if (Repeat)
{
case RepeatPingParameterSet:
Count = int.MaxValue;
break;
case TcpPortParameterSet:
SetCountForTcpTest();
break;
Count = int.MaxValue;
}
else if (ParameterSetName == TcpPortParameterSet)
{
SetCountForTcpTest();
}
}

Expand All @@ -265,21 +264,22 @@ protected override void ProcessRecord()

foreach (var targetName in TargetName)
{
switch (ParameterSetName)
if (MtuSize)
{
ProcessMTUSize(targetName);
}
else if (Traceroute)
{
ProcessTraceroute(targetName);
}
else if (ParameterSetName == TcpPortParameterSet)
{
ProcessConnectionByTCPPort(targetName);
}
else
{
case DefaultPingParameterSet:
case RepeatPingParameterSet:
ProcessPing(targetName);
break;
case MtuSizeDetectParameterSet:
ProcessMTUSize(targetName);
break;
case TraceRouteParameterSet:
ProcessTraceroute(targetName);
break;
case TcpPortParameterSet:
ProcessConnectionByTCPPort(targetName);
break;
// None of the switch parameters are true: handle default ping or -Repeat
ProcessPing(targetName);
}
}
}
Expand All @@ -298,7 +298,7 @@ protected override void StopProcessing()

private void SetCountForTcpTest()
{
if (Repeat.IsPresent)
if (Repeat)
{
Count = int.MaxValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ Describe "Test-Connection" -tags "CI", "RequireSudoOnUnix" {
$pingResults.Where( { $_.Status -eq 'Success' }, 'Default', 1 ).BufferSize | Should -Be 32
}
}

It "Repeat with explicit false should behave like default ping" {
# -Repeat:$false should behave the same as not specifying -Repeat
$pingResults = Test-Connection $targetAddress -Repeat:$false

# Should get exactly 4 pings (the default Count value)
$pingResults.Count | Should -Be 4
$pingResults[0].Address | Should -BeExactly $targetAddress
}
}

Context "MTUSizeDetect" {
Expand Down Expand Up @@ -291,6 +300,16 @@ Describe "Test-Connection" -tags "CI", "RequireSudoOnUnix" {
$result | Should -BeOfType Int32
$result | Should -BeGreaterThan 0
}

It "MtuSize with explicit false should behave like default ping" {
# -MtuSize:$false should behave the same as not specifying -MtuSize (default ping)
$pingResults = Test-Connection $targetAddress -MtuSize:$false

# Should return PingStatus, not PingMtuStatus
$pingResults[0] | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingStatus
# Should get 4 pings (the default Count value)
$pingResults.Count | Should -Be 4
}
}

Context "TraceRoute" {
Expand Down Expand Up @@ -332,6 +351,16 @@ Describe "Test-Connection" -tags "CI", "RequireSudoOnUnix" {

$results.Hostname | Should -Not -BeNullOrEmpty
}

It "Traceroute with explicit false should behave like default ping" {
# -Traceroute:$false should behave the same as not specifying -Traceroute (default ping)
$pingResults = Test-Connection $targetAddress -Traceroute:$false

# Should return PingStatus, not TraceStatus
$pingResults[0] | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingStatus
# Should get 4 pings (the default Count value)
$pingResults.Count | Should -Be 4
}
}
}

Expand Down
Loading