mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Add Export-Alias Pester Unit Test
This commit is contained in:
1 parent
b7be84a0b0
commit
04f3936b6b
1 file changed
+158
-33
@@ -1,33 +1,158 @@
|
|||||||
Describe "Export-Alias" {
|
Describe "Export-Alias DRT Unit Tests" -Tags DRT{
|
||||||
$testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory
|
$testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory
|
||||||
$testAliases = "TestAliases"
|
$testAliases = "TestAliases"
|
||||||
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
||||||
|
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
New-Item -Path $testAliasDirectory -ItemType Directory -Force
|
New-Item -Path $testAliasDirectory -ItemType Directory -Force
|
||||||
}
|
remove-item alias:abcd* -force
|
||||||
|
remove-item alias:ijkl* -force
|
||||||
It "Should be able to create a file in the specified location"{
|
set-alias abcd01 efgh01
|
||||||
Export-Alias $fulltestpath
|
set-alias abcd02 efgh02
|
||||||
|
set-alias abcd03 efgh03
|
||||||
Test-Path $fulltestpath | Should be $true
|
set-alias abcd04 efgh04
|
||||||
}
|
set-alias ijkl01 mnop01
|
||||||
|
set-alias ijkl02 mnop02
|
||||||
It "Should create a file with the list of aliases that match the expected list" {
|
set-alias ijkl03 mnop03
|
||||||
Export-Alias $fulltestpath
|
set-alias ijkl04 mnop04
|
||||||
|
}
|
||||||
Test-Path $fulltestpath | Should Be $true
|
|
||||||
|
AfterEach {
|
||||||
$actual = Get-Content $fulltestpath | Sort
|
Remove-Item -Path $testAliasDirectory -Recurse -Force
|
||||||
$expected = $(Get-Command -CommandType Alias)
|
}
|
||||||
|
|
||||||
for ( $i=0; $i -lt $expected.Length; $i++)
|
It "Export-Alias for exist file should work"{
|
||||||
{
|
New-Item -Path $fulltestpath -ItemType File -Force
|
||||||
# We loop through the expected list and not the other because the output writes some comments to the file.
|
{Export-Alias $fulltestpath}| Should Not Throw
|
||||||
$expected[$i] | Should Match $actual[$i].Name
|
}
|
||||||
}
|
|
||||||
|
It "Export-Alias Resolve To Multiple will throw PSInvalidOperationException" {
|
||||||
}
|
try {
|
||||||
|
Export-Alias *
|
||||||
Remove-Item -Path $testAliasDirectory -Recurse -Force
|
Throw "Execution OK"
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
$_.FullyQualifiedErrorId | Should be "ReadWriteMultipleFilesNotSupported,Microsoft.PowerShell.Commands.ExportAliasCommand"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias with Invalid Scope will throw PSArgumentException" {
|
||||||
|
try {
|
||||||
|
Export-Alias $fulltestpath -scope foobar
|
||||||
|
Throw "Execution OK"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$_.FullyQualifiedErrorId | Should be "Argument,Microsoft.PowerShell.Commands.ExportAliasCommand"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias for Default"{
|
||||||
|
Export-Alias $fulltestpath abcd01 -passthru
|
||||||
|
$fulltestpath| Should ContainExactly '"abcd01","efgh01","","None"'
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias As CSV"{
|
||||||
|
Export-Alias $fulltestpath abcd01 -As CSV -passthru
|
||||||
|
$fulltestpath| Should ContainExactly '"abcd01","efgh01","","None"'
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias As CSV With Description"{
|
||||||
|
Export-Alias $fulltestpath abcd01 -As CSV -description "My Aliases" -passthru
|
||||||
|
$fulltestpath| Should ContainExactly '"abcd01","efgh01","","None"'
|
||||||
|
$fulltestpath| Should ContainExactly "My Aliases"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias As CSV With Multiline Description"{
|
||||||
|
Export-Alias $fulltestpath abcd01 -As CSV -description "My Aliases\nYour Aliases\nEveryones Aliases" -passthru
|
||||||
|
$fulltestpath| Should ContainExactly '"abcd01","efgh01","","None"'
|
||||||
|
$fulltestpath| Should ContainExactly "My Aliases"
|
||||||
|
$fulltestpath| Should ContainExactly "Your Aliases"
|
||||||
|
$fulltestpath| Should ContainExactly "Everyones Aliases"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias As Script"{
|
||||||
|
Export-Alias $fulltestpath abcd01 -As Script -passthru
|
||||||
|
$fulltestpath| Should ContainExactly 'set-alias -Name:"abcd01" -Value:"efgh01" -Description:"" -Option:"None"'
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias As Script With Multiline Description"{
|
||||||
|
Export-Alias $fulltestpath abcd01 -As Script -description "My Aliases\nYour Aliases\nEveryones Aliases" -passthru
|
||||||
|
$fulltestpath| Should ContainExactly 'set-alias -Name:"abcd01" -Value:"efgh01" -Description:"" -Option:"None"'
|
||||||
|
$fulltestpath| Should ContainExactly "My Aliases"
|
||||||
|
$fulltestpath| Should ContainExactly "Your Aliases"
|
||||||
|
$fulltestpath| Should ContainExactly "Everyones Aliases"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias for Force Test"{
|
||||||
|
Export-Alias $fulltestpath abcd01
|
||||||
|
Export-Alias $fulltestpath abcd02 -force
|
||||||
|
$fulltestpath| Should Not ContainExactly '"abcd01","efgh01","","None"'
|
||||||
|
$fulltestpath| Should ContainExactly '"abcd02","efgh02","","None"'
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias for Force ReadOnly Test for linux" -Skip:$IsWindows {
|
||||||
|
Export-Alias $fulltestpath abcd01
|
||||||
|
chmod 444 $fulltestpath
|
||||||
|
try{
|
||||||
|
Export-Alias $fulltestpath abcd02
|
||||||
|
}
|
||||||
|
catch{
|
||||||
|
$_.FullyQualifiedErrorId | Should be "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand"
|
||||||
|
}
|
||||||
|
Export-Alias $fulltestpath abcd03 -force
|
||||||
|
$fulltestpath| Should Not ContainExactly '"abcd01","efgh01","","None"'
|
||||||
|
$fulltestpath| Should Not ContainExactly '"abcd02","efgh02","","None"'
|
||||||
|
$fulltestpath| Should ContainExactly '"abcd03","efgh03","","None"'
|
||||||
|
chmod 777 $fulltestpath
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Export-Alias for Force ReadOnly Test for windows" -Skip:($IsLinux -Or $IsOSX) {
|
||||||
|
Export-Alias $fulltestpath abcd01
|
||||||
|
attrib +r $fulltestpath
|
||||||
|
try{
|
||||||
|
Export-Alias $fulltestpath abcd02
|
||||||
|
}
|
||||||
|
catch{
|
||||||
|
$_.FullyQualifiedErrorId | Should be "FileOpenFailure,Microsoft.PowerShell.Commands.ExportAliasCommand"
|
||||||
|
}
|
||||||
|
Export-Alias $fulltestpath abcd03 -force
|
||||||
|
$fulltestpath| Should Not ContainExactly '"abcd01","efgh01","","None"'
|
||||||
|
$fulltestpath| Should Not ContainExactly '"abcd02","efgh02","","None"'
|
||||||
|
$fulltestpath| Should ContainExactly '"abcd03","efgh03","","None"'
|
||||||
|
attrib -r $fulltestpath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe "Export-Alias" {
|
||||||
|
$testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory
|
||||||
|
$testAliases = "TestAliases"
|
||||||
|
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
||||||
|
|
||||||
|
BeforeEach {
|
||||||
|
New-Item -Path $testAliasDirectory -ItemType Directory -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should be able to create a file in the specified location"{
|
||||||
|
Export-Alias $fulltestpath
|
||||||
|
|
||||||
|
Test-Path $fulltestpath | Should be $true
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should create a file with the list of aliases that match the expected list" {
|
||||||
|
Export-Alias $fulltestpath
|
||||||
|
|
||||||
|
Test-Path $fulltestpath | Should Be $true
|
||||||
|
|
||||||
|
$actual = Get-Content $fulltestpath | Sort
|
||||||
|
$expected = $(Get-Command -CommandType Alias)
|
||||||
|
|
||||||
|
for ( $i=0; $i -lt $expected.Length; $i++)
|
||||||
|
{
|
||||||
|
# We loop through the expected list and not the other because the output writes some comments to the file.
|
||||||
|
$expected[$i] | Should Match $actual[$i].Name
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Remove-Item -Path $testAliasDirectory -Recurse -Force
|
||||||
|
}
|
||||||
Reference in new issue
Block a user