-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add Unblock-File tests #2954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Unblock-File tests #2954
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| function Test-UnblockFile { | ||
| try { | ||
| Get-Content -Path $testfilepath -Stream Zone.Identifier -ErrorAction Stop | Out-Null | ||
| } | ||
| catch { | ||
| if ($_.FullyQualifiedErrorId -eq "GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand") { | ||
| return $true | ||
| } | ||
| } | ||
|
|
||
| return $false | ||
| } | ||
|
|
||
| Describe "Unblock-File" -Tags "CI" { | ||
|
|
||
| BeforeAll { | ||
| if ( ! $IsWindows ) | ||
| { | ||
| $origDefaults = $PSDefaultParameterValues.Clone() | ||
| $PSDefaultParameterValues['it:skip'] = $true | ||
|
|
||
| } else { | ||
| $testfilepath = Join-Path -Path $TestDrive -ChildPath testunblockfile.ttt | ||
| } | ||
| } | ||
|
|
||
| AfterAll { | ||
| if ( ! $IsWindows ){ | ||
| $global:PSDefaultParameterValues = $origDefaults | ||
| } | ||
| } | ||
|
|
||
| BeforeEach { | ||
| if ( $IsWindows ){ | ||
| Set-Content -Value "[ZoneTransfer]`r`nZoneId=4" -Path $testfilepath -Stream Zone.Identifier | ||
| } | ||
| } | ||
|
|
||
| It "With '-Path': no file exist" { | ||
| try { | ||
| Unblock-File -Path nofileexist.ttt -ErrorAction Stop | ||
| throw "No Exception!" | ||
| } | ||
| catch { | ||
| $_.FullyQualifiedErrorId | Should Be "FileNotFound,Microsoft.PowerShell.Commands.UnblockFileCommand" | ||
| } | ||
| } | ||
|
|
||
| It "With -LiteralPath': no file exist" { | ||
| try { | ||
| Unblock-File -LiteralPath nofileexist.ttt -ErrorAction Stop | ||
| throw "No Exception!" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer this to be following so that the logs on failure have good error message. throw "No Exception thrown when FileNotFound,Microsoft.PowerShell.Commands.UnblockFileCommand was expected"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have two "cons" (for all comments). If
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with this being kept as "No Exception" But as of the function returning a $true or $false, I would prefer it to be like below as the error will give us the line number where the should is located : function Test-UnblockFile {
try {
Get-Content -Path $testfilepath -Stream Zone.Identifier -ErrorAction Stop | Out-Null
throw "No Exception"
}
catch {
$_.FullyQualifiedErrorId | Should Be "GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand"
}
}
It "With '-Path': file exist" {
Unblock-File -Path $testfilepath
Test-UnblockFile
}
It "With '-LiteralPath': file exist" {
Unblock-File -LiteralPath $testfilepath
Test-UnblockFile
}
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we move
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adityapatwardhan Issue #2973 was closed. Please continue the review. |
||
| } | ||
| catch { | ||
| $_.FullyQualifiedErrorId | Should Be "FileNotFound,Microsoft.PowerShell.Commands.UnblockFileCommand" | ||
| } | ||
| } | ||
|
|
||
| It "With '-Path': file exist" { | ||
| Unblock-File -Path $testfilepath | ||
| Test-UnblockFile | Should Be $true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this test fails, the error message would be Expected : {True} But was : {False}. This does not help in debugging the failure. I would prefer this to be like: Unblock-File -Path $testfilepath
try {
Get-Content -Path $testfilepath -Stream Zone.Identifier -ErrorAction Stop | Out-Null
throw "No exception thrown when GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand was expected"|
}
catch {
$_.FullyQualifiedErrorId | Should Be "GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand"
} |
||
| } | ||
|
|
||
| It "With '-LiteralPath': file exist" { | ||
| Unblock-File -LiteralPath $testfilepath | ||
| Test-UnblockFile | Should Be $true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with this being kept as "No Exception"