Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iSazonov committed May 29, 2020
1 parent 513ab65 commit 6c461d5
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ Describe "Extended FileSystem Provider Tests for Get-ChildItem cmdlet" -Tags "CI
}

Context 'Validate Get-ChildItem -Path -Include' {
It 'Get-ChildItem -Path $-Include "*.txt"' -Pending:$true { # Pending due to a bug
It 'Get-ChildItem -Path -Include "*.txt"' -Pending:$true { # Pending due to a bug
$result = Get-ChildItem -Path $rootDir -Include "*.txt"
$result.Count | Should -Be 1
$result | Should -BeOfType System.IO.FileInfo
Expand Down Expand Up @@ -650,4 +650,28 @@ Describe "Extended FileSystem Provider Tests for Get-ChildItem cmdlet" -Tags "CI
$result.Where({ $_.Name -like "*2.*" -or $_.Name -like "*3.*" }) | Should -BeOfType System.IO.FileInfo
}
}

Context 'Validate Get-ChildItem -Path for path that access denied' {
It 'Get-ChildItem writes an error if root path is not accessable' -Skip:(!$IsWindows) {
$path = "C:\Windows\System32\spool\SERVERS"
$errorId = "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"
{ Get-ChildItem -Path $path -ErrorAction Stop } | Should -Throw -ErrorId $errorId
{ Get-ChildItem -Path $path -Recurse -ErrorAction Stop } | Should -Throw -ErrorId $errorId
{ Get-ChildItem -Path $path -Name -ErrorAction Stop } | Should -Throw -ErrorId $errorId
{ Get-ChildItem -Path $path -Recurse -Name -ErrorAction Stop } | Should -Throw -ErrorId "System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand"
}

It 'Get-ChildItem returns unaccessable folders and writes errors' -Skip:(!$IsWindows) {
$path = "C:\Windows\System32\spool"
$result1 = Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue -ErrorVariable error1 | Select-Object -ExpandProperty Name
$result1 | Should -Contain "SERVERS"
$error1.Count | Should -BeGreaterThan 0
$error1[0].FullyQualifiedErrorId | Should -BeExactly "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"

$result2 = Get-ChildItem -Path $path -Recurse -Name -ErrorAction SilentlyContinue -ErrorVariable error2
$result2 | Should -Contain "SERVERS"
$error2.Count | Should -BeGreaterThan 0
$error2[0].FullyQualifiedErrorId | Should -BeExactly "DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand"
}
}
}

0 comments on commit 6c461d5

Please sign in to comment.