Skip to content

Commit 317b85b

Browse files
Skip tests on Windows PowerShell
1 parent 4981e99 commit 317b85b

1 file changed

Lines changed: 19 additions & 34 deletions

File tree

test/DscResource/PSResourceGetDSCResource.Tests.ps1

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,19 @@ Describe 'E2E tests for PSResourceList resource' -Tags 'CI' {
339339
SetupDsc
340340

341341
## The installed modules will not be found in the Windows PowerShell module path because DSC will install them in the PowerShell 7 context.
342-
## Therefore, when running these tests on Windows PowerShell, we need to invoke PowerShell 7 explicitly
342+
## Therefore, skipping these tests on Windows PowerShell is necessary because the modules installed by DSC will not be visible in that environment.
343343
$isOnWindowsPowerShell = $PSVersionTable.PSVersion.Major -lt 6
344+
345+
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
346+
$PSDefaultParameterValues['it:skip'] = $isOnWindowsPowerShell
347+
}
348+
349+
AfterAll {
350+
$global:PSDefaultParameterValues = $originalDefaultParameterValues
344351
}
345352

346353
It 'Can Install testmodule99' {
354+
347355
$mod = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Version '0.0.93'
348356
if ($mod) {
349357
$mod | Uninstall-PSResource -ErrorAction SilentlyContinue
@@ -352,14 +360,10 @@ Describe 'E2E tests for PSResourceList resource' -Tags 'CI' {
352360
$configPath = Join-Path -Path $PSScriptRoot -ChildPath 'configs/psresourcegetlist.install.dsc.yaml'
353361
& $script:dscExe config set -f $configPath
354362

355-
if ($isOnWindowsPowerShell) {
356-
$psresource = pwsh -Command "Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Version '0.0.93'"
357-
}
358-
else {
359-
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Version '0.0.93'
360-
}
361-
$psresource.Name | Should -Be 'testmodule99'
362-
$psresource.Version | Should -Be '0.0.93'
363+
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Version '0.0.93'
364+
365+
$psresource.Name | Should -Be 'testmodule99'
366+
$psresource.Version | Should -Be '0.0.93'
363367
}
364368

365369
It 'Can Uninstall testmodule99' {
@@ -368,13 +372,7 @@ Describe 'E2E tests for PSResourceList resource' -Tags 'CI' {
368372
$configPath = Join-Path -Path $PSScriptRoot -ChildPath 'configs/psresourcegetlist.uninstall.dsc.yaml'
369373
& $script:dscExe config set -f $configPath
370374

371-
if ($isOnWindowsPowerShell) {
372-
$psresource = pwsh -Command "Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Version '0.0.93'"
373-
}
374-
else {
375-
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Version '0.0.93'
376-
}
377-
375+
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue -Version '0.0.93'
378376
$psresource | Should -BeNullOrEmpty
379377
}
380378

@@ -401,12 +399,7 @@ Describe 'E2E tests for PSResourceList resource' -Tags 'CI' {
401399
$configPath = Join-Path -Path $PSScriptRoot -ChildPath 'configs/psresourcegetlist.moddeps.install.dsc.yaml'
402400
& $script:dscExe config set -f $configPath
403401

404-
if ($isOnWindowsPowerShell) {
405-
$psresource = pwsh -Command "Get-PSResource -Name $modulelist -ErrorAction SilentlyContinue"
406-
}
407-
else {
408-
$psresource = Get-PSResource -Name $modulelist -ErrorAction SilentlyContinue
409-
}
402+
$psresource = Get-PSResource -Name $modulelist -ErrorAction SilentlyContinue
410403

411404
$psresource | Should -HaveCount 5
412405
}
@@ -420,12 +413,8 @@ Describe 'E2E tests for PSResourceList resource' -Tags 'CI' {
420413
$configPath = Join-Path -Path $PSScriptRoot -ChildPath 'configs/psresourcegetlist.prerelease.install.dsc.yaml'
421414
& $script:dscExe config set -f $configPath
422415

423-
if ($isOnWindowsPowerShell) {
424-
$psresource = pwsh -Command "Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue"
425-
}
426-
else {
427-
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue
428-
}
416+
417+
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue
429418

430419
$psresource | Should -HaveCount 2
431420

@@ -447,12 +436,8 @@ Describe 'E2E tests for PSResourceList resource' -Tags 'CI' {
447436
$configPath = Join-Path -Path $PSScriptRoot -ChildPath 'configs/psresourcegetlist.oneexisting.install.dsc.yaml'
448437
& $script:dscExe config set -f $configPath
449438

450-
if ($isOnWindowsPowerShell) {
451-
$psresource = pwsh -Command "Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue"
452-
}
453-
else {
454-
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue
455-
}
439+
440+
$psresource = Get-PSResource -Name 'testmodule99' -ErrorAction SilentlyContinue
456441

457442
$psresource | Should -HaveCount 2
458443

0 commit comments

Comments
 (0)