Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions test/powershell/dsc/dsc.profileresource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
BeforeAll {
$DSC_ROOT = $env:DSC_ROOT
$skipCleanup = $false

if (-not (Test-Path -Path $DSC_ROOT)) {
$skipCleanup = $true
throw "DSC_ROOT environment variable is not set or path does not exist."
}

Expand Down Expand Up @@ -40,6 +42,10 @@ Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
New-Item -Path $testProfilePathCurrentUserAllHosts -Value $testProfileContent -Force -ItemType File
}
AfterAll {
if ($skipCleanup) {
return
}

# Restore original profile
$testProfilePathCurrentUserCurrentHost = $PROFILE.CurrentUserCurrentHost
if (Test-Path "$TestDrive/currentuser-currenthost-profile.bak") {
Expand Down Expand Up @@ -118,16 +124,19 @@ Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
Describe "DSC PowerShell Profile resource elevated tests" -Tag "CI", 'RequireAdminOnWindows', 'RequireSudoOnUnix' {
BeforeAll {
$DSC_ROOT = $env:DSC_ROOT
$skipCleanup = $false

if (-not (Test-Path -Path $DSC_ROOT)) {
$skipCleanup = $true
throw "DSC_ROOT environment variable is not set or path does not exist."
}

Write-Verbose "DSC_ROOT is set to $DSC_ROOT" -Verbose
$pathSeparator = [System.IO.Path]::PathSeparator

$env:PATH += "$pathSeparator$DSC_ROOT"
$originalPath = $env:PATH

$pathSeparator = [System.IO.Path]::PathSeparator
$env:PATH += "$pathSeparator$DSC_ROOT"
$env:PATH += "$pathSeparator$PSHome"

Write-Verbose "Updated PATH to include DSC_ROOT: $env:PATH" -Verbose
Expand All @@ -151,11 +160,12 @@ Describe "DSC PowerShell Profile resource elevated tests" -Tag "CI", 'RequireAdm
$testProfilePathAllUsersAllHosts = $PROFILE.AllUsersAllHosts
Copy-Item -Path $testProfilePathAllUsersAllHosts -Destination "$TestDrive/allusers-allhosts-profile.bak" -Force -ErrorAction SilentlyContinue
New-Item -Path $testProfilePathAllUsersAllHosts -Value $testProfileContent -Force -ItemType File

$originalPath = $env:PATH
$env:PATH += "$pathSeparator$PSHome"
}
AfterAll {
if ($skipCleanup) {
return
}

$env:PATH = $originalPath

$testProfilePathAllUsersCurrentHost = $PROFILE.AllUsersCurrentHost
Expand Down
Loading