2020-03-24 19:08:37 +01:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 18:23:53 +01:00
|
|
|
# Licensed under the MIT License.
|
|
|
|
<############################################################################################
|
2017-09-30 01:28:15 +02:00
|
|
|
# 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 {
|
2020-01-13 20:35:33 +01:00
|
|
|
$powershell = Join-Path -Path $PSHOME -ChildPath "pwsh"
|
2017-10-18 02:25:11 +02:00
|
|
|
|
2017-09-30 01:28:15 +02:00
|
|
|
$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'
|
2020-05-07 14:00:30 +02:00
|
|
|
New-VHD -Path $tmpVhdPath -SizeBytes 5mb -Dynamic -ErrorAction Stop
|
2017-09-30 01:28:15 +02:00
|
|
|
Remove-Item $tmpVhdPath
|
2020-01-13 20:25:09 +01:00
|
|
|
$VHDToolsNotFound = (Get-Module Hyper-V).PrivateData.ImplicitRemoting -eq $true
|
2019-11-18 19:44:55 +01:00
|
|
|
Remove-Module Hyper-V
|
2017-09-30 01:28:15 +02:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{ $VHDToolsNotFound = $true }
|
|
|
|
}
|
2017-10-18 02:25:11 +02:00
|
|
|
|
2017-09-30 01:28:15 +02:00
|
|
|
Context "Validating automounting FileSystem drives" {
|
2017-10-18 02:25:11 +02:00
|
|
|
|
2017-09-30 01:28:15 +02:00
|
|
|
It "Test automounting using subst.exe" -Skip:$SubstNotFound {
|
2018-03-29 06:08:23 +02:00
|
|
|
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -FullPath '$substDir'" | Should -BeExactly "Drive found"
|
2017-09-30 01:28:15 +02:00
|
|
|
}
|
2017-10-18 02:25:11 +02:00
|
|
|
|
2017-09-30 01:28:15 +02:00
|
|
|
It "Test automounting using New-VHD/Mount-VHD" -Skip:$VHDToolsNotFound {
|
2018-03-29 06:08:23 +02:00
|
|
|
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -VHDPath '$vhdPath'" | Should -BeExactly "Drive found"
|
2017-09-30 01:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context "Validating automounting FileSystem drives from modules" {
|
2017-10-18 02:25:11 +02:00
|
|
|
|
2017-09-30 01:28:15 +02:00
|
|
|
It "Test automounting using subst.exe" -Skip:$SubstNotFound {
|
2018-03-29 06:08:23 +02:00
|
|
|
& $powershell -noprofile -command "& '$AutomountSubstDriveScriptPath' -useModule -FullPath '$substDir'" | Should -BeExactly "Drive found"
|
2017-09-30 01:28:15 +02:00
|
|
|
}
|
2017-10-18 02:25:11 +02:00
|
|
|
|
2017-09-30 01:28:15 +02:00
|
|
|
It "Test automounting using New-VHD/Mount-VHD" -Skip:$VHDToolsNotFound {
|
|
|
|
$vhdPath = Join-Path $TestDrive 'TestAutomountVHD.vhd'
|
2018-03-29 06:08:23 +02:00
|
|
|
& $powershell -noprofile -command "& '$AutomountVHDDriveScriptPath' -useModule -VHDPath '$vhdPath'" | Should -BeExactly "Drive found"
|
2017-09-30 01:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|