File size: 5,341 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "Basic Alias Provider Tests" -Tags "CI" {
Context "Validate basic PSDrive Cmdlets" {
BeforeAll {
#just use same location as TestDrive for simplicity
$psDriveRoot = "TestDrive:"
$psDriveName = "PsTestDriveName"
}
BeforeEach {
New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot > $null
}
AfterEach {
Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue
}
It "Create a new PSDrive" {
try {
$newDrive = New-PSDrive -Name "NewDifferentPSDrive" -PSProvider FileSystem -Root $psDriveRoot
$newDrive.Name | Should -BeExactly "NewDifferentPSDrive"
$newDrive.Root | Should -BeExactly (Convert-Path $psDriveRoot)
}
finally {
Remove-PSDrive -Name "NewDifferentPSDrive" -Force -ErrorAction SilentlyContinue
}
}
It "Read data from a PSDrive" {
$driveProp = Get-ItemProperty ${psDriveName}:
$driveProp.PSDrive.Name | Should -BeExactly $psDriveName
}
It "Remove the PSDrive" {
$existsBefore = Test-Path "${psDriveName}:\"
Remove-PSDrive -Name ${psDriveName} -ErrorAction SilentlyContinue
$existsAfter = Test-Path "${psDriveName}:\"
$existsBefore | Should -BeTrue
$existsAfter | Should -BeFalse
}
It "Verify 'Used' and 'Free' script properties" {
$drive = Get-PSDrive -Name $psDriveName
$drive.Used | Should -Not -BeNullOrEmpty
$drive.Free | Should -Not -BeNullOrEmpty
}
}
}
Describe "Extended Alias Provider Tests" -Tags "Feature" {
BeforeAll {
#just use same location as TestDrive for simplicity
$psDriveRoot = "TestDrive:"
$psDriveName = "PsTestDriveName"
}
Context "Valdiate New-PSDrive Cmdlet Parameters" {
AfterEach {
Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue
}
It "Verify Description" {
$result = New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Description "Test PSDrive to remove"
$result.Description | Should -BeExactly "Test PSDrive to remove"
}
It "Verify Confirm can be bypassed" {
$result = New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Confirm:$false
$result.Name | Should -BeExactly $psDriveName
}
It "Verify WhatIf" {
New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -WhatIf > $null
{ Get-PSDrive -Name $psDriveName -ErrorAction Stop } | Should -Throw -ErrorId "GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand"
}
It "Verify Scope" {
New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Description "Test PSDrive to remove" -Scope Local > $null
$foundGlobal = $true
{ $globalDrive = Get-PSDrive -Name $psDriveName -Scope Global -ErrorAction Stop } | Should -Throw -ErrorId "GetDriveNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand"
$localDrive = Get-PSDrive -Name $psDriveName -Scope Local
$localDrive.Name | Should -BeExactly $psDriveName
}
It "Verify '-Persist' parameter is not available on UNIX" -Skip:($IsWindows) {
{ New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Persist -Description "Test PSDrive to remove" } | Should -Throw -ErrorId "NamedParameterNotFound,Microsoft.PowerShell.Commands.NewPSDriveCommand"
}
}
Context "Valdiate Get-PSDrive Cmdlet Parameters" {
BeforeEach {
New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot > $null
}
AfterEach {
Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue
}
It "Verify Name" {
$result = Get-PSDrive -Name $psDriveName
$result.Name | Should -BeExactly $psDriveName
}
It "Verify PSProvider" {
$result = Get-PSDrive -PSProvider "Alias"
$result.Name | Should -BeExactly "Alias"
}
It "Verify Scope" {
$result = Get-PSDrive -Scope 1 #scope 1 because drive was created in BeforeAll
$result.Name -contains $psDriveName | Should -BeTrue
}
}
Context "Valdiate Remove-PSDrive Cmdlet Parameters" {
BeforeEach {
New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot > $null
}
AfterEach {
Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue
}
It "Verify Confirm can be bypassed" {
Remove-PSDrive $psDriveName -Confirm:$false
$exists = Test-Path -Path $psDriveName
$exists | Should -BeFalse
}
It "Verify WhatIf" {
Remove-PSDrive $psDriveName -WhatIf
$exists = Test-Path -Path "${psDriveName}:"
$exists | Should -BeTrue
}
}
}
|