Skip to content

Commit 31694f3

Browse files
DanGoughsintaxasn
authored andcommitted
Extend Copy-ADTFile.Tests.ps1 to cover basic -LiteralPath usage
1 parent 0aa0bde commit 31694f3

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

src/Tests/Unit/Copy-ADTFile.Tests.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ Describe 'Copy-ADTFile'-ForEach @(
7272
"$DestinationPath\test.txt" | Should -Exist
7373
}
7474

75+
It 'Copies a single file via -LiteralPath($PreCreateDestination = $<PreCreateDestination>; $FileCopyMode = $<FileCopyMode>)' {
76+
Copy-ADTFile -LiteralPath "$SourcePath\test.txt" -Destination $DestinationPath -FileCopyMode $FileCopyMode
77+
78+
"$DestinationPath\test.txt" | Should -Exist
79+
}
80+
7581
It 'Copies a single file with a new filename ($PreCreateDestination = $<PreCreateDestination>; $FileCopyMode = $<FileCopyMode>)' {
7682
Copy-ADTFile -Path "$SourcePath\test.txt" -Destination "$DestinationPath\new.txt" -FileCopyMode $FileCopyMode
7783

@@ -94,6 +100,14 @@ Describe 'Copy-ADTFile'-ForEach @(
94100
"$DestinationPath\test.txt" | Should -Exist
95101
}
96102

103+
It 'Copies a file via LiteralPath where only filename is supplied prefixed with .\ ($PreCreateDestination = $<PreCreateDestination>; $FileCopyMode = $<FileCopyMode>)' {
104+
Push-Location $SourcePath
105+
Copy-ADTFile -LiteralPath '.\test.txt' -Destination $DestinationPath -FileCopyMode $FileCopyMode
106+
Pop-Location
107+
108+
"$DestinationPath\test.txt" | Should -Exist
109+
}
110+
97111
It 'Copies a file where both source and destination folders are prefixed with .\ ($PreCreateDestination = $<PreCreateDestination>; $FileCopyMode = $<FileCopyMode>)' {
98112
Push-Location $TestDrive
99113
Copy-ADTFile -Path '.\Source\test.txt' -Destination '.\Destination' -FileCopyMode $FileCopyMode
@@ -116,6 +130,12 @@ Describe 'Copy-ADTFile'-ForEach @(
116130
"$DestinationPath\test.txt" | Should -Exist
117131
}
118132

133+
It 'Copies a file to and from a UNC path via LiteralPath ($PreCreateDestination = $<PreCreateDestination>; $FileCopyMode = $<FileCopyMode>)' {
134+
Copy-ADTFile -LiteralPath "$($SourcePath.Replace('C:\', '\\localhost\c$\'))\test.txt" -Destination $DestinationPath.Replace('C:\', '\\localhost\c$\') -FileCopyMode $FileCopyMode
135+
136+
"$DestinationPath\test.txt" | Should -Exist
137+
}
138+
119139
Context 'Tests to be performed with and without recursion/flatten' -ForEach @(
120140
@{ Recurse = $false; Flatten = $false }
121141
@{ Recurse = $true; Flatten = $false }
@@ -149,6 +169,34 @@ Describe 'Copy-ADTFile'-ForEach @(
149169
}
150170
}
151171

172+
It 'Copies a folder via -LiteralPath ($PreCreateDestination = $<PreCreateDestination>; $Recurse = $<Recurse>; $Flatten = $<Flatten>; $FileCopyMode = $<FileCopyMode>)' {
173+
Copy-ADTFile -LiteralPath $SourcePath -Destination $DestinationPath -Recurse:$Recurse -Flatten:$Flatten -FileCopyMode $FileCopyMode
174+
175+
if ($Flatten)
176+
{
177+
"$DestinationPath\test.txt" | Should -Exist
178+
"$DestinationPath\test1.txt" | Should -Exist
179+
"$DestinationPath\test2.txt" | Should -Exist
180+
"$DestinationPath\test3.txt" | Should -Exist
181+
}
182+
else
183+
{
184+
if ($FileCopyMode -eq 'Robocopy')
185+
{
186+
# Known issue - "$DestinationPath\Source\test.txt" will only exist when using Robocopy
187+
"$DestinationPath\Source\test.txt" | Should -Exist
188+
}
189+
if ($Recurse)
190+
{
191+
"$DestinationPath\Source\Subfolder1\test1.txt" | Should -Exist
192+
}
193+
else
194+
{
195+
"$DestinationPath\Source\Subfolder1\test1.txt" | Should -Not -Exist
196+
}
197+
}
198+
}
199+
152200
It 'Copies files with a * as the source filename ($PreCreateDestination = $<PreCreateDestination>; $Recurse = $<Recurse>; $Flatten = $<Flatten>; $FileCopyMode = $<FileCopyMode>)' {
153201
Copy-ADTFile -Path "$SourcePath\*" -Destination $DestinationPath -Recurse:$Recurse -Flatten:$Flatten -FileCopyMode $FileCopyMode
154202

0 commit comments

Comments
 (0)