add SCP symlink coverage to Pester Tests in place of Bash tests
This commit is contained in:
parent
42e182fd4a
commit
a6248c1e5b
|
@ -27,23 +27,29 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
$DestinationFilePath = Join-Path $DestinationDir $fileName1
|
||||
$NestedSourceDir= Join-Path $SourceDir "nested"
|
||||
$NestedSourceFilePath = Join-Path $NestedSourceDir $fileName2
|
||||
$tmpDir = Join-Path $testDir "tmpDir"
|
||||
$tmpDirFilePath = Join-Path $tmpDir $fileName1
|
||||
$tmpDirSymLinkPath = Join-Path $SourceDir "SymLinkDir"
|
||||
$null = New-Item $SourceDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
$null = New-Item $NestedSourceDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
$null = New-Item $tmpDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
$null = New-item -path $SourceFilePath -ItemType file -force -ErrorAction SilentlyContinue
|
||||
$null = New-item -path $NestedSourceFilePath -ItemType file -force -ErrorAction SilentlyContinue
|
||||
$null = New-item -path $tmpDirFilePath -ItemType file -force -ErrorAction SilentlyContinue
|
||||
"Test content111" | Set-content -Path $SourceFilePath
|
||||
"Test content333" | Set-content -Path $SourceFilePath3
|
||||
"Test content in nested dir" | Set-content -Path $NestedSourceFilePath
|
||||
"Test content in tmp dir for sym link" | Set-content -Path $tmpDirFilePath
|
||||
$null = New-Item -Path $tmpDirSymLinkPath -ItemType SymbolicLink -Value $tmpDir
|
||||
$null = New-Item $DestinationDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
$sshcmd = (get-command ssh).Path
|
||||
|
||||
# for symlink tests
|
||||
$SourceDirSymLinkName = "SourceDirSymLink"
|
||||
$SourceDirSymLink = Join-Path $testDir $SourceDirSymLinkName
|
||||
$tmpDir = Join-Path $testDir "tmpDir"
|
||||
$tmpDirFilePath = Join-Path $tmpDir $fileName1
|
||||
$null = New-Item $SourceDirSymLink -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
$null = New-Item $tmpDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
$null = New-item -path $tmpDirFilePath -ItemType file -force -ErrorAction SilentlyContinue
|
||||
"Test content in tmp dir for sym link" | Set-content -Path $tmpDirFilePath
|
||||
$SymLinkName = "SymLinkDir"
|
||||
$SymLinkDir = Join-Path $SourceDirSymLink $SymLinkName
|
||||
$null = New-Item -Path $SymLinkDir -ItemType SymbolicLink -Value $tmpDir
|
||||
|
||||
$server = $OpenSSHTestInfo["Target"]
|
||||
$port = $OpenSSHTestInfo["Port"]
|
||||
$ssouser = $OpenSSHTestInfo["SSOUser"]
|
||||
|
@ -121,6 +127,27 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
}
|
||||
)
|
||||
|
||||
$testData2 = @(
|
||||
@{
|
||||
Title = 'symlink copy from local dir to remote dir'
|
||||
Source = $SourceDirSymLink
|
||||
Destination = "test_target:$DestinationDir"
|
||||
Options = "-r -p -c aes128-ctr"
|
||||
},
|
||||
@{
|
||||
Title = 'symlink copy from local dir to local dir'
|
||||
Source = $SourceDirSymLink
|
||||
Destination = $DestinationDir
|
||||
Options = "-r "
|
||||
},
|
||||
@{
|
||||
Title = 'symlink copy from remote dir to local dir'
|
||||
Source = "test_target:$SourceDirSymLink"
|
||||
Destination = $DestinationDir
|
||||
Options = "-C -r -q"
|
||||
}
|
||||
)
|
||||
|
||||
# for the first time, delete the existing log files.
|
||||
if ($OpenSSHTestInfo['DebugMode'])
|
||||
{
|
||||
|
@ -159,6 +186,10 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
{
|
||||
Get-Item $SourceDir | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
if(-not [string]::IsNullOrEmpty($SourceDirSymLink))
|
||||
{
|
||||
Get-Item $SourceDirSymLink | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
if(-not [string]::IsNullOrEmpty($DestinationDir))
|
||||
{
|
||||
Get-Item $DestinationDir | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
@ -167,7 +198,7 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
}
|
||||
|
||||
BeforeAll {
|
||||
$null = New-Item $DestinationDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
#$null = New-Item $DestinationDir -ItemType directory -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
|
@ -176,14 +207,12 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
$tI++
|
||||
}
|
||||
|
||||
|
||||
It 'File copy: <Title> ' -TestCases:$testData {
|
||||
param([string]$Title, $Source, $Destination, [string]$Options)
|
||||
iex "scp $Options $Source $Destination"
|
||||
$LASTEXITCODE | Should Be 0
|
||||
#validate file content. DestPath is the path to the file.
|
||||
CheckTarget -target $DestinationFilePath | Should Be $true
|
||||
|
||||
$equal = @(Compare-Object (Get-ChildItem -path $SourceFilePath) (Get-ChildItem -path $DestinationFilePath) -Property Name, Length ).Length -eq 0
|
||||
$equal | Should Be $true
|
||||
|
||||
|
@ -210,6 +239,10 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
$equal | Should Be $true
|
||||
}
|
||||
|
||||
write-host "source dir:"
|
||||
Get-ChildItem -Recurse -path $SourceDir | write-host
|
||||
write-host "destination dir:"
|
||||
Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) | write-host
|
||||
$equal = @(Compare-Object (Get-ChildItem -Recurse -path $SourceDir) (Get-ChildItem -Recurse -path (join-path $DestinationDir $SourceDirName) ) -Property Name, Length).Length -eq 0
|
||||
$equal | Should Be $true
|
||||
|
||||
|
@ -220,6 +253,16 @@ Describe "Tests for scp command" -Tags "CI" {
|
|||
}
|
||||
}
|
||||
|
||||
It 'Directory with symlink recursive copy: <Title> ' -TestCases:$testData2 {
|
||||
param([string]$Title, $Source, $Destination, [string]$Options)
|
||||
|
||||
iex "scp $Options $Source $Destination"
|
||||
$LASTEXITCODE | Should Be 0
|
||||
$expectedFilepath = join-path $DestinationDir $SourceDirSymLinkName $SymLinkName $fileName1
|
||||
CheckTarget -target $expectedFilepath | Should Be $true
|
||||
Get-Content $expectedFilepath | Should Be "Test content in tmp dir for sym link"
|
||||
}
|
||||
|
||||
It 'File copy: path contains wildcards ' {
|
||||
$Source = Join-Path $SourceDir $wildcardFileName2
|
||||
scp -p $Source $DestinationDir
|
||||
|
|
Loading…
Reference in New Issue