forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pester.AutomountedDrives.Tests.ps1
57 lines (46 loc) · 2.57 KB
/
Pester.AutomountedDrives.Tests.ps1
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
<############################################################################################
# File: Pester.AutomountedDrives.Tests.ps1
# Pester.AutomountedDrives.Tests suite contains Tests that are
# used for validating automounted PowerShell drives.
############################################################################################>
$script:TestSourceRoot = $PSScriptRoot
Describe "Test suite for validating automounted PowerShell drives" -Tags @('Feature', 'Slow', 'RequireAdminOnWindows') {
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "pwsh"
$AutomountVHDDriveScriptPath = Join-Path $script:TestSourceRoot 'AutomountVHDDrive.ps1'
$vhdPath = Join-Path $TestDrive 'TestAutomountVHD.vhd'
$AutomountSubstDriveScriptPath = Join-Path $script:TestSourceRoot 'AutomountSubstDrive.ps1'
$substDir = Join-Path (Join-Path $TestDrive 'TestAutomountSubstDrive') 'TestDriveRoot'
New-Item $substDir -ItemType Directory -Force | Out-Null
$SubstNotFound = $false
try { subst.exe } catch { $SubstNotFound = $true }
$VHDToolsNotFound = $false
try
{
$tmpVhdPath = Join-Path $TestDrive 'TestVHD.vhd'
New-VHD -path $tmpVhdPath -SizeBytes 5mb -Dynamic -ErrorAction Stop
Remove-Item $tmpVhdPath
}
catch
{ $VHDToolsNotFound = $true }
}
Context "Validating automounting FileSystem drives" {
It "Test automounting using subst.exe" -Skip:$SubstNotFound {
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -FullPath '$substDir'" | Should -BeExactly "Drive found"
}
It "Test automounting using New-VHD/Mount-VHD" -Skip:$VHDToolsNotFound {
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -VHDPath '$vhdPath'" | Should -BeExactly "Drive found"
}
}
Context "Validating automounting FileSystem drives from modules" {
It "Test automounting using subst.exe" -Skip:$SubstNotFound {
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -useModule -FullPath '$substDir'" | Should -BeExactly "Drive found"
}
It "Test automounting using New-VHD/Mount-VHD" -Skip:$VHDToolsNotFound {
$vhdPath = Join-Path $TestDrive 'TestAutomountVHD.vhd'
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -useModule -VHDPath '$vhdPath'" | Should -BeExactly "Drive found"
}
}
}