Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Get-PSDrive.Tests.ps1117 linesDownload Raw Back to Microsoft.PowerShell.Management
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Get-PSDrive" -Tags "CI" {4 5    It "Should not throw" {6	Get-PSDrive | Should -Not -BeNullOrEmpty7    }8 9    It "Should have a name and a length property" {10	(Get-PSDrive).Name        | Should -Not -BeNullOrEmpty11	(Get-PSDrive).Root.Length | Should -Not -BeLessThan 112    }13 14    It "Should be able to be called with the gdr alias" {15	{ gdr } | Should -Not -Throw16 17	gdr | Should -Not -BeNullOrEmpty18    }19 20    It "Should be the same output between Get-PSDrive and gdr" {21	$alias  = gdr22	$actual = Get-PSDrive23 24 25	$alias | Should -BeExactly $actual26    }27 28    It "Should return drive info"{29        (Get-PSDrive Env).Name        | Should -BeExactly Env30        (Get-PSDrive Alias).Name      | Should -BeExactly Alias31 32        if ($IsWindows)33        {34            (Get-PSDrive Cert).Root       | Should -Be \35            (Get-PSDrive C).Provider.Name | Should -BeExactly FileSystem36        }37        else38        {39            (Get-PSDrive /).Provider.Name | Should -BeExactly FileSystem40        }41    }42 43    It "Should be able to access a drive using the PSProvider switch" {44	(Get-PSDrive -PSProvider FileSystem).Name.Length | Should -BeGreaterThan 045    }46 47    It "Should return true that a drive that does not exist"{48	!(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should -BeTrue49	Get-PSDrive fake -ErrorAction SilentlyContinue    | Should -BeNullOrEmpty50    }51    It "Should be able to determine the amount of free space of a drive" {52        $dInfo = Get-PSDrive TESTDRIVE53        $dInfo.Free -ge 0 | Should -BeTrue54    }55    It "Should be able to determine the amount of Used space of a drive" {56        $dInfo = Get-PSDrive TESTDRIVE57        $dInfo.Used -ge 0 | Should -BeTrue58    }59}60 61Describe "Temp: drive" -Tag Feature {62    It "TEMP: drive exists" {63        $res = Get-PSDrive Temp64        $res.Name | Should -BeExactly "Temp"65        $res.Root | Should -BeExactly ([System.IO.Path]::GetTempPath())66    }67}68 69Describe "Get-PSDrive for network path" -Tags "CI","RequireAdminOnWindows" {70 71    It 'Check P/Invoke GetDosDevice/QueryDosDevice' -Skip:(-not $IsWindows) {72        $UsedDrives  = Get-PSDrive | Select-Object -ExpandProperty Name73        $PSDriveName = 'D'..'Z' | Where-Object -FilterScript {$_ -notin $UsedDrives} | Get-Random74 75        subst "$($PSDriveName):" \\localhost\c$\Windows76 77        $drive = Get-PSDrive $PSDriveName78        $drive.DisplayRoot | Should -BeExactly '\\localhost\c$\Windows'79        subst "$($PSDriveName):" /D80    }81 82    It 'Check P/Invoke for WNetGetConnection with small buffer: <SmallBuffer>' -Skip:(-not $IsWindows) -TestCases @(83        @{ SmallBuffer = $false }84        @{ SmallBuffer = $true }85    ) {86        param ($SmallBuffer)87 88        $UsedDrives  = Get-PSDrive | Select-Object -ExpandProperty Name89        $PSDriveName = 'D'..'Z' | Where-Object -FilterScript {$_ -notin $UsedDrives} | Get-Random90 91        $drive = New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root \\localhost\c$\Windows -Persist92        try {93            if ($SmallBuffer) {94                [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('WNetGetConnectionBufferSize', 4)95            }96 97            # The result is cached in the current instance, use a new98            # PowerShell instance to test out WNetGetConnection code.99            $ps = [PowerShell]::Create()100            $actual = $ps.AddCommand('Get-PSDrive').AddParameter('Name', $PSDriveName).Invoke()101            if ($ps.HadErrors) {102                throw $ps.Streams.Error[0]103            }104 105            $actual.Name | Should -BeExactly $PSDriveName106            $actual.DisplayRoot | Should -BeExactly '\\localhost\c$\Windows'107        }108        finally {109            $drive | Remove-PSDrive110 111            if ($SmallBuffer) {112                [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('WNetGetConnectionBufferSize', -1)113            }114        }115    }116}117