Skip to content

Commit 65e2c7a

Browse files
committed
Move installation of test modules to bootstrapping
So we can get this working on OneBranch.
1 parent 8d7e430 commit 65e2c7a

File tree

3 files changed

+18
-50
lines changed

3 files changed

+18
-50
lines changed

test/PSDesiredStateConfiguration.Tests.ps1

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@
22
# Licensed under the MIT License.
33

44
BeforeDiscovery {
5-
Function global:Install-ModuleIfMissing {
6-
param(
7-
[parameter(Mandatory)]
8-
[String]
9-
$Name,
10-
[version]
11-
$MinimumVersion,
12-
[switch]
13-
$SkipPublisherCheck,
14-
[switch]
15-
$Force
16-
)
17-
18-
$module = Get-Module -Name $Name -ListAvailable -ErrorAction Ignore | Sort-Object -Property Version -Descending | Select-Object -First 1
19-
20-
if (!$module -or $module.Version -lt $MinimumVersion) {
21-
Write-Verbose "Installing module '$Name' ..." -Verbose
22-
Install-Module -Name $Name -Force -SkipPublisherCheck:$SkipPublisherCheck.IsPresent
23-
}
24-
}
25-
265
Function global:Test-IsInvokeDscResourceEnable {
276
return ($PSVersionTable.PSVersion.Major -ge 7)
287
}
@@ -87,7 +66,6 @@ Describe "Test PSDesiredStateConfiguration" {
8766
BeforeAll {
8867
$origProgress = $global:ProgressPreference
8968
$global:ProgressPreference = 'SilentlyContinue'
90-
Install-ModuleIfMissing -Name PSDscResources
9169
$testCases = @(
9270
@{
9371
TestCaseName = 'case mismatch in resource name'
@@ -162,10 +140,6 @@ Describe "Test PSDesiredStateConfiguration" {
162140
$origProgress = $global:ProgressPreference
163141
$global:ProgressPreference = 'SilentlyContinue'
164142

165-
Install-ModuleIfMissing -Name PSDscResources -Force
166-
167-
# Install PowerShellGet only if PowerShellGet 2.2.1 or newer does not exist
168-
Install-ModuleIfMissing -Name PowerShellGet -MinimumVersion '2.2.1'
169143
$module = Get-Module PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
170144

171145
$psGetModuleSpecification = @{ModuleName = $module.Name; ModuleVersion = $module.Version.ToString() }
@@ -273,7 +247,6 @@ Describe "Test PSDesiredStateConfiguration" {
273247
BeforeAll {
274248
$origProgress = $global:ProgressPreference
275249
$global:ProgressPreference = 'SilentlyContinue'
276-
Install-ModuleIfMissing -Name XmlContentDsc -Force
277250
$classTestCases = @(
278251
@{
279252
TestCaseName = 'Good case'
@@ -340,11 +313,6 @@ Describe "Test PSDesiredStateConfiguration" {
340313
BeforeAll {
341314
$origProgress = $global:ProgressPreference
342315
$global:ProgressPreference = 'SilentlyContinue'
343-
$module = Get-InstalledModule -Name PsDscResources -ErrorAction Ignore
344-
if ($module) {
345-
Write-Verbose "removing PSDscResources, tests will re-install..." -Verbose
346-
Uninstall-Module -Name PsDscResources -AllVersions -Force
347-
}
348316
}
349317

350318
AfterAll {
@@ -372,22 +340,14 @@ Describe "Test PSDesiredStateConfiguration" {
372340
}
373341
)
374342

375-
Install-ModuleIfMissing -Name PowerShellGet -Force -SkipPublisherCheck -MinimumVersion '2.2.1'
376-
Install-ModuleIfMissing -Name xWebAdministration
377343
$module = Get-Module PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
378344

379345
$psGetModuleSpecification = @{ModuleName = $module.Name; ModuleVersion = $module.Version.ToString() }
380346
}
381347
it "Set method should work" -Skip:(!(Test-IsInvokeDscResourceEnable)) {
382-
if (!-not $IsWindows) {
383-
$result = Invoke-DscResource -Name PSModule -ModuleName $psGetModuleSpecification -Method set -Property @{
384-
Name = 'PsDscResources'
385-
InstallationPolicy = 'Trusted'
386-
}
387-
}
388-
else {
389-
# workraound because of https://github.com/PowerShell/PowerShellGet/pull/529
390-
Install-ModuleIfMissing -Name PsDscResources -Force
348+
$result = Invoke-DscResource -Name PSModule -ModuleName $psGetModuleSpecification -Method set -Property @{
349+
Name = 'PsDscResources'
350+
InstallationPolicy = 'Trusted'
391351
}
392352

393353
$result.RebootRequired | Should -BeFalse
@@ -443,7 +403,7 @@ Describe "Test PSDesiredStateConfiguration" {
443403
$moduleName="TestEmbeddedDSCResource"
444404
$embObj = @(New-Object -TypeName psobject -Property @{embclassprop="property1"})
445405

446-
Install-ModuleIfMissing -Name $moduleName -Force
406+
Install-Module -Name $moduleName -Force
447407

448408
$resource = Get-DscResource -Name $resourceName -Module $moduleName -ErrorAction Stop
449409
$resource | Should -Not -BeNullOrEmpty
@@ -515,10 +475,6 @@ Describe "Test PSDesiredStateConfiguration" {
515475
}
516476

517477
Context "Class Based Resources" {
518-
BeforeAll {
519-
Install-ModuleIfMissing -Name XmlContentDsc -Force
520-
}
521-
522478
AfterAll {
523479
$Global:ProgressPreference = $origProgress
524480
}

test/configuration.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Describe "DSC MOF Compilation" {
88
}
99

1010
It "Should be able to compile a MOF using PSModule resource" {
11-
if ($env:GITHUB_ACTIONS -eq 'true') {
12-
Set-ItResult -Skipped -Because "Running in GitHub Actions"
11+
if ($env:GITHUB_ACTIONS -eq 'true' -or $env:TF_BUILD -eq 'true') {
12+
Set-ItResult -Skipped -Because "Does not work in CI"
1313
}
1414

1515
if (-not $IsWindows) {

tools/installPSResources.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,16 @@ Install-PSResource -Verbose -TrustRepository -RequiredResource @{
2121
version = "5.7.1"
2222
repository = $PSRepository
2323
}
24+
PSDscResources = @{
25+
version = "2.12.0.0"
26+
repository = $PSRepository
27+
}
28+
XmlContentDsc = @{
29+
version = "0.0.1"
30+
repository = $PSRepository
31+
}
32+
xWebAdministration = @{
33+
version = "3.3.0"
34+
repository = $PSRepository
35+
}
2436
}

0 commit comments

Comments
 (0)