8000 Add negative tests for Copy-Item over remote sessions (#6231) · PowerShell/PowerShell@31cef2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 31cef2a

Browse files
kalgizdaxian-dbw
authored andcommitted
Add negative tests for Copy-Item over remote sessions (#6231)
1 parent 06b0bb2 commit 31cef2a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,32 @@ Describe "Validate Copy-Item Remotely" -Tags "CI" {
483483
Copy-Item -Path $filePath -FromSession $s -Destination $destinationFolderPath
484484
ValidateCopyItemOperationForAlternateDataStream -filePath $filePath -streamName $streamName -expectedStreamContent $streamContent
485485
}
486+
487+
It "Copy file to the same directory fails." {
488+
$filePath = CreateTestFile
489+
{ Copy-Item -Path $filePath -Destination $sourceDirectory -FromSession $s -ErrorAction Stop } | ShouldBeErrorId "System.IO.IOException,WriteException"
490+
}
491+
492+
It "Copy directory with a -Destination parameter given as a file path fails." {
493+
$filePath = CreateTestFile
494+
$folderToCopy = GetDestinationFolderPath
495+
{ Copy-Item -Path $folderToCopy -Destination $filePath -FromSession $s -ErrorAction Stop } | ShouldBeErrorId "CopyError,Microsoft.PowerShell.Commands.CopyItemCommand"
496+
}
497+
498+
It "Copy-Item parameters -FromSession and -ToSession are mutually exclusive." {
499+
try
500+
87F1 {
501+
$s1 = New-PSSession -ComputerName . -ErrorAction SilentlyContinue
502+
$s1 | Should Not BeNullOrEmpty
503+
$filePath = CreateTestFile
504+
$destinationFolderPath = GetDestinationFolderPath
505+
{ Copy-Item -Path $filePath -Destination $destinationFolderPath -FromSession $s -ToSession $s1 -ErrorAction Stop } | ShouldBeErrorId "InvalidInput,Microsoft.PowerShell.Commands.CopyItemCommand"
506+
}
507+
finally
508+
{
509+
Remove-PSSession -Session $s1 -ErrorAction SilentlyContinue
510+
}
511+
}
486512
}
487513

488514
Context "Validate Copy-Item Remotely using wildcards" {

0 commit comments

Comments
 (0)
0