|
2 | 2 | # Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | 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 | | - |
26 | 5 | Function global:Test-IsInvokeDscResourceEnable { |
27 | 6 | return ($PSVersionTable.PSVersion.Major -ge 7) |
28 | 7 | } |
@@ -87,7 +66,6 @@ Describe "Test PSDesiredStateConfiguration" { |
87 | 66 | BeforeAll { |
88 | 67 | $origProgress = $global:ProgressPreference |
89 | 68 | $global:ProgressPreference = 'SilentlyContinue' |
90 | | - Install-ModuleIfMissing -Name PSDscResources |
91 | 69 | $testCases = @( |
92 | 70 | @{ |
93 | 71 | TestCaseName = 'case mismatch in resource name' |
@@ -162,10 +140,6 @@ Describe "Test PSDesiredStateConfiguration" { |
162 | 140 | $origProgress = $global:ProgressPreference |
163 | 141 | $global:ProgressPreference = 'SilentlyContinue' |
164 | 142 |
|
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' |
169 | 143 | $module = Get-Module PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1 |
170 | 144 |
|
171 | 145 | $psGetModuleSpecification = @{ModuleName = $module.Name; ModuleVersion = $module.Version.ToString() } |
@@ -273,7 +247,6 @@ Describe "Test PSDesiredStateConfiguration" { |
273 | 247 | BeforeAll { |
274 | 248 | $origProgress = $global:ProgressPreference |
275 | 249 | $global:ProgressPreference = 'SilentlyContinue' |
276 | | - Install-ModuleIfMissing -Name XmlContentDsc -Force |
277 | 250 | $classTestCases = @( |
278 | 251 | @{ |
279 | 252 | TestCaseName = 'Good case' |
@@ -340,11 +313,6 @@ Describe "Test PSDesiredStateConfiguration" { |
340 | 313 | BeforeAll { |
341 | 314 | $origProgress = $global:ProgressPreference |
342 | 315 | $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 | | - } |
348 | 316 | } |
349 | 317 |
|
350 | 318 | AfterAll { |
@@ -372,22 +340,14 @@ Describe "Test PSDesiredStateConfiguration" { |
372 | 340 | } |
373 | 341 | ) |
374 | 342 |
|
375 | | - Install-ModuleIfMissing -Name PowerShellGet -Force -SkipPublisherCheck -MinimumVersion '2.2.1' |
376 | | - Install-ModuleIfMissing -Name xWebAdministration |
377 | 343 | $module = Get-Module PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1 |
378 | 344 |
|
379 | 345 | $psGetModuleSpecification = @{ModuleName = $module.Name; ModuleVersion = $module.Version.ToString() } |
380 | 346 | } |
381 | 347 | 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' |
391 | 351 | } |
392 | 352 |
|
393 | 353 | $result.RebootRequired | Should -BeFalse |
@@ -443,7 +403,7 @@ Describe "Test PSDesiredStateConfiguration" { |
443 | 403 | $moduleName="TestEmbeddedDSCResource" |
444 | 404 | $embObj = @(New-Object -TypeName psobject -Property @{embclassprop="property1"}) |
445 | 405 |
|
446 | | - Install-ModuleIfMissing -Name $moduleName -Force |
| 406 | + Install-Module -Name $moduleName -Force |
447 | 407 |
|
448 | 408 | $resource = Get-DscResource -Name $resourceName -Module $moduleName -ErrorAction Stop |
449 | 409 | $resource | Should -Not -BeNullOrEmpty |
@@ -515,10 +475,6 @@ Describe "Test PSDesiredStateConfiguration" { |
515 | 475 | } |
516 | 476 |
|
517 | 477 | Context "Class Based Resources" { |
518 | | - BeforeAll { |
519 | | - Install-ModuleIfMissing -Name XmlContentDsc -Force |
520 | | - } |
521 | | - |
522 | 478 | AfterAll { |
523 | 479 | $Global:ProgressPreference = $origProgress |
524 | 480 | } |
|
0 commit comments