mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Respect -Repeat/-MtuSize/-Traceroute:$false in Test-Connection (#26479)
This commit is contained in:
+22
-22
@@ -242,14 +242,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,21 +264,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
foreach (var targetName in TargetName)
|
||||
{
|
||||
switch (ParameterSetName)
|
||||
if (MtuSize)
|
||||
{
|
||||
case DefaultPingParameterSet:
|
||||
case RepeatPingParameterSet:
|
||||
ProcessPing(targetName);
|
||||
break;
|
||||
case MtuSizeDetectParameterSet:
|
||||
ProcessMTUSize(targetName);
|
||||
break;
|
||||
case TraceRouteParameterSet:
|
||||
ProcessTraceroute(targetName);
|
||||
break;
|
||||
case TcpPortParameterSet:
|
||||
ProcessConnectionByTCPPort(targetName);
|
||||
break;
|
||||
ProcessMTUSize(targetName);
|
||||
}
|
||||
else if (Traceroute)
|
||||
{
|
||||
ProcessTraceroute(targetName);
|
||||
}
|
||||
else if (ParameterSetName == TcpPortParameterSet)
|
||||
{
|
||||
ProcessConnectionByTCPPort(targetName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// None of the switch parameters are true: handle default ping or -Repeat
|
||||
ProcessPing(targetName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,7 +298,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private void SetCountForTcpTest()
|
||||
{
|
||||
if (Repeat.IsPresent)
|
||||
if (Repeat)
|
||||
{
|
||||
Count = int.MaxValue;
|
||||
}
|
||||
|
||||
@@ -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" {
|
||||
@@ -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" {
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user