Remove not initialized variable $IsElevated from test in New-Item.Tests.ps1 (#6746)
* Remove not initialized variable from PowerShell tests * Separate the tests that requires no elevation from the others.
This commit is contained in:
parent
3b1a4a4722
commit
cda6ef175c
|
@ -206,16 +206,26 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') {
|
|||
Remove-Item $FullyQualifiedLink -Force
|
||||
}
|
||||
|
||||
It "Should error correctly when failing to create a symbolic link" -Skip:($IsWindows -or $IsElevated) {
|
||||
Write-Host "Iselevated: $IsElevated"
|
||||
# This test expects that /sbin exists but is not writable by the user
|
||||
{ New-Item -ItemType SymbolicLink -Path "/sbin/powershell-test" -Target $FullyQualifiedFolder -ErrorAction Stop } |
|
||||
Should -Throw -ErrorId "NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand"
|
||||
}
|
||||
|
||||
It "New-Item -ItemType SymbolicLink should understand directory path ending with slash" {
|
||||
$folderName = [System.IO.Path]::GetRandomFileName()
|
||||
$symbolicLinkPath = New-Item -ItemType SymbolicLink -Path "$tmpDirectory/$folderName/" -Value "/bar/"
|
||||
$symbolicLinkPath | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Describe "New-Item with links fails for non elevated user." -Tags "CI" {
|
||||
BeforeAll {
|
||||
$tmpDirectory = $TestDrive
|
||||
$testfile = "testfile.txt"
|
||||
$testfolder = "newDirectory"
|
||||
$testlink = "testlink"
|
||||
$FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile
|
||||
$FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder
|
||||
}
|
||||
|
||||
It "Should error correctly when failing to create a symbolic link" {
|
||||
# This test expects that /sbin exists but is not writable by the user
|
||||
{ New-Item -ItemType SymbolicLink -Path "/sbin/powershell-test" -Target $FullyQualifiedFolder -ErrorAction Stop } |
|
||||
Should -Throw -ErrorId "NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue