Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
PSDrive.Tests.ps1139 linesDownload Raw Back to Microsoft.PowerShell.Management
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Basic Alias Provider Tests" -Tags "CI" {5    Context "Validate basic PSDrive Cmdlets" {6        BeforeAll {7            #just use same location as TestDrive for simplicity8            $psDriveRoot = "TestDrive:"9            $psDriveName = "PsTestDriveName"10        }11 12        BeforeEach {13            New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot > $null14        }15 16        AfterEach {17            Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue18        }19 20        It "Create a new PSDrive" {21            try {22                $newDrive = New-PSDrive -Name "NewDifferentPSDrive" -PSProvider FileSystem -Root $psDriveRoot23                $newDrive.Name | Should -BeExactly "NewDifferentPSDrive"24                $newDrive.Root | Should -BeExactly (Convert-Path $psDriveRoot)25            }26            finally {27                Remove-PSDrive -Name "NewDifferentPSDrive" -Force -ErrorAction SilentlyContinue28            }29        }30 31        It "Read data from a PSDrive" {32            $driveProp = Get-ItemProperty ${psDriveName}:33            $driveProp.PSDrive.Name | Should -BeExactly $psDriveName34        }35 36        It "Remove the PSDrive" {37            $existsBefore = Test-Path "${psDriveName}:\"38            Remove-PSDrive -Name ${psDriveName} -ErrorAction SilentlyContinue39            $existsAfter = Test-Path "${psDriveName}:\"40            $existsBefore | Should -BeTrue41            $existsAfter | Should -BeFalse42        }43 44        It "Verify 'Used' and 'Free' script properties" {45            $drive = Get-PSDrive -Name $psDriveName46            $drive.Used | Should -Not -BeNullOrEmpty47            $drive.Free | Should -Not -BeNullOrEmpty48        }49    }50}51 52Describe "Extended Alias Provider Tests" -Tags "Feature" {53    BeforeAll {54        #just use same location as TestDrive for simplicity55        $psDriveRoot = "TestDrive:"56        $psDriveName = "PsTestDriveName"57    }58 59    Context "Valdiate New-PSDrive Cmdlet Parameters" {60        AfterEach {61            Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue62        }63 64        It "Verify Description" {65            $result = New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Description "Test PSDrive to remove"66            $result.Description | Should -BeExactly "Test PSDrive to remove"67        }68 69        It "Verify Confirm can be bypassed" {70            $result = New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Confirm:$false71            $result.Name | Should -BeExactly $psDriveName72        }73 74        It "Verify WhatIf" {75            New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -WhatIf > $null76            { Get-PSDrive -Name $psDriveName -ErrorAction Stop } | Should -Throw -ErrorId "GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand"77        }78 79        It "Verify Scope" {80            New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Description "Test PSDrive to remove" -Scope Local > $null81            $foundGlobal = $true82            { $globalDrive = Get-PSDrive -Name $psDriveName -Scope Global -ErrorAction Stop } | Should -Throw -ErrorId "GetDriveNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand"83            $localDrive = Get-PSDrive -Name $psDriveName -Scope Local84            $localDrive.Name | Should -BeExactly $psDriveName85        }86 87        It "Verify '-Persist' parameter is not available on UNIX" -Skip:($IsWindows) {88                { New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot -Persist -Description "Test PSDrive to remove" } | Should -Throw -ErrorId "NamedParameterNotFound,Microsoft.PowerShell.Commands.NewPSDriveCommand"89        }90    }91 92    Context "Valdiate Get-PSDrive Cmdlet Parameters" {93        BeforeEach {94            New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot > $null95        }96 97        AfterEach {98            Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue99        }100 101        It "Verify Name" {102            $result = Get-PSDrive -Name $psDriveName103            $result.Name | Should -BeExactly $psDriveName104        }105 106        It "Verify PSProvider" {107            $result = Get-PSDrive -PSProvider "Alias"108            $result.Name | Should -BeExactly "Alias"109        }110 111        It "Verify Scope" {112            $result = Get-PSDrive -Scope 1 #scope 1 because drive was created in BeforeAll113            $result.Name -contains $psDriveName | Should -BeTrue114        }115    }116 117    Context "Valdiate Remove-PSDrive Cmdlet Parameters" {118        BeforeEach {119            New-PSDrive -Name $psDriveName -PSProvider FileSystem -Root $psDriveRoot > $null120        }121 122        AfterEach {123            Remove-PSDrive -Name $psDriveName -Force -ErrorAction SilentlyContinue124        }125 126        It "Verify Confirm can be bypassed" {127            Remove-PSDrive $psDriveName -Confirm:$false128            $exists = Test-Path -Path $psDriveName129            $exists | Should -BeFalse130        }131 132        It "Verify WhatIf" {133            Remove-PSDrive $psDriveName -WhatIf134            $exists = Test-Path -Path "${psDriveName}:"135            $exists | Should -BeTrue136        }137    }138}139