MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" {5 Context "Validate New-PSDrive Cmdlet with -Persist switch." {6 BeforeEach {7 $UsedDrives = Get-PSDrive | Select-Object -ExpandProperty Name8 $PSDriveName = 'D'..'Z' | Where-Object -FilterScript {$_ -notin $UsedDrives} | Get-Random9 $RemoteShare = "\\$env:COMPUTERNAME\$($env:SystemDrive.replace(':','$\'))"10 }11 12 AfterEach {13 Remove-PSDrive -Name $PSDriveName -Force -ErrorAction SilentlyContinue14 }15 16 It "Should not throw exception for persistent PSDrive creation." -Skip:(-not $IsWindows) {17 { New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Not -Throw18 }19 20 It "Network drive initialization on pwsh startup DisplayRoot should have value of share" -Skip:(-not $IsWindows) {21 $null = New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop22 $drive = pwsh -noprofile -outputformat XML -command "Get-PSDrive -Name $PSDriveName"23 $drive.DisplayRoot | Should -Be $RemoteShare.TrimEnd('\')24 }25 26 It "Should throw exception if root is not a remote share." -Skip:(-not $IsWindows) {27 { New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root "TestDrive:\" -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveRootNotNetworkPath'28 }29 30 It "Should throw exception if PSDrive is not a drive letter supported by operating system." -Skip:(-not $IsWindows) {31 $PSDriveName = 'AB'32 { New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence'33 }34 }35}36 