1+ Function Install-ModuleIfMissing
2+ {
3+ param (
4+ [parameter (Mandatory )]
5+ [String ]
6+ $Name ,
7+ [version ]
8+ $MinimumVersion ,
9+ [switch ]
10+ $SkipPublisherCheck ,
11+ [switch ]
12+ $Force
13+ )
14+
15+ $module = Get-Module - Name $Name - ListAvailable - ErrorAction Ignore | Sort-Object - Property Version - Descending | Select-Object - First 1
16+
17+ if (! $module -or $module.Version -lt $MinimumVersion )
18+ {
19+ Write-Verbose " Installing module '$Name ' ..." - Verbose
20+ Install-Module - Name $Name - Force - SkipPublisherCheck:$SkipPublisherCheck.IsPresent
21+ }
22+ }
23+
124Describe " Test PSDesiredStateConfiguration" - tags CI {
225 Context " Module loading" {
326 BeforeAll {
@@ -27,11 +50,99 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
2750 $commands | Where-Object {$_.Name -eq ' Get-DscResource' } | Should -Not - BeNullOrEmpty
2851 }
2952 }
53+ Context " Get-DscResource - Composite Resources" {
54+ BeforeAll {
55+ $origProgress = $global :ProgressPreference
56+ $global :ProgressPreference = ' SilentlyContinue'
57+ Install-ModuleIfMissing - Name PSDscResources
58+ $testCases = @ (
59+ @ {
60+ TestCaseName = ' case mismatch in resource name'
61+ Name = ' groupset'
62+ ModuleName = ' PSDscResources'
63+ }
64+ @ {
65+ TestCaseName = ' Both names have matching case'
66+ Name = ' GroupSet'
67+ ModuleName = ' PSDscResources'
68+ }
69+ @ {
70+ TestCaseName = ' case mismatch in module name'
71+ Name = ' GroupSet'
72+ ModuleName = ' psdscResources'
73+ }
74+ )
75+ }
76+ AfterAll {
77+ $Global :ProgressPreference = $origProgress
78+ }
79+ it " should be able to get <Name> - <TestCaseName>" - TestCases $testCases {
80+ param ($Name )
81+
82+ if ($IsWindows )
83+ {
84+ Set-ItResult - Pending - Because " Will only find script from PSDesiredStateConfiguration without modulename"
85+ }
86+
87+ if ($IsLinux )
88+ {
89+ Set-ItResult - Pending - Because " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/26"
90+ }
91+
92+ $resource = Get-DscResource - Name $name
93+ $resource | Should -Not - BeNullOrEmpty
94+ $resource.Name | Should - Be $Name
95+ $resource.ImplementationDetail | Should - BeNullOrEmpty
96+ }
97+
98+ it " should be able to get <Name> from <ModuleName> - <TestCaseName>" - TestCases $testCases {
99+ param ($Name , $ModuleName , $PendingBecause )
100+
101+ if ($IsLinux )
102+ {
103+ Set-ItResult - Pending - Because " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/26"
104+ }
105+
106+ if ($PendingBecause )
107+ {
108+ Set-ItResult - Pending - Because $PendingBecause
109+ }
110+ $resource = Get-DscResource - Name $Name - Module $ModuleName
111+ $resource | Should -Not - BeNullOrEmpty
112+ $resource.Name | Should - Be $Name
113+ $resource.ImplementationDetail | Should - BeNullOrEmpty
114+ }
115+ }
30116 Context " Get-DscResource - ScriptResources" {
31117 BeforeAll {
32118 $origProgress = $global :ProgressPreference
33119 $global :ProgressPreference = ' SilentlyContinue'
120+
121+ Install-ModuleIfMissing - Name PSDscResources - Force
122+
123+ Install-ModuleIfMissing - Name PowerShellGet - MinimumVersion ' 2.2.1'
124+ $module = Get-Module PowerShellGet - ListAvailable | Sort-Object - Property Version - Descending | Select-Object - First 1
125+
126+ $psGetModuleSpecification = @ {ModuleName = $module.Name ;ModuleVersion = $module.Version.ToString ()}
127+ $psGetModuleCount = @ (Get-Module PowerShellGet - ListAvailable).Count
34128 $testCases = @ (
129+ @ {
130+ TestCaseName = ' case mismatch in resource name'
131+ Name = ' script'
132+ ModuleName = ' PSDscResources'
133+ }
134+ @ {
135+ TestCaseName = ' Both names have matching case'
136+ Name = ' Script'
137+ ModuleName = ' PSDscResources'
138+ }
139+ @ {
140+ TestCaseName = ' case mismatch in module name'
141+ Name = ' Script'
142+ ModuleName = ' psdscResources'
143+ }
144+ <#
145+ Add these back when PowerShellGet is fixed https://github.com/PowerShell/PowerShellGet/pull/529
35146 @{
36147 TestCaseName = 'case mismatch in resource name'
37148 Name = 'PsModule'
@@ -46,9 +157,8 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
46157 TestCaseName = 'case mismatch in module name'
47158 Name = 'PSModule'
48159 ModuleName = 'powershellget'
49- # Linux issue: https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12
50- PendingBecause = ' https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12'
51160 }
161+ #>
52162 )
53163 }
54164 AfterAll {
@@ -58,34 +168,45 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
58168 it " should be able to get <Name> - <TestCaseName>" - TestCases $testCases {
59169 param ($Name )
60170
61- if ($IsLinux -or $ IsWindows )
171+ if ($IsWindows )
62172 {
63- Set-ItResult - Pending - Because " https://github.com/PowerShell/ PSDesiredStateConfiguration/issues/15 "
173+ Set-ItResult - Pending - Because " Will only find script from PSDesiredStateConfiguration without modulename "
64174 }
65175
66- $resource = Get-DscResource - Name $name
67- $resource | Should -Not - BeNullOrEmpty
68- $resource.Name | Should - Be $Name
176+ if ($PendingBecause )
177+ {
178+ Set-ItResult - Pending - Because $PendingBecause
179+ }
180+
181+ $resources = @ (Get-DscResource - Name $name )
182+ $resources | Should -Not - BeNullOrEmpty
183+ foreach ($resource in $resource )
184+ {
185+ $resource.Name | Should - Be $Name
186+ }
69187 }
70188
71189 it " should be able to get <Name> from <ModuleName> - <TestCaseName>" - TestCases $testCases {
72190 param ($Name , $ModuleName , $PendingBecause )
73191
74192 if ($IsLinux )
75193 {
76- Set-ItResult - Pending - Because " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12"
194+ Set-ItResult - Pending - Because " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12 and https://github.com/PowerShell/PowerShellGet/pull/529 "
77195 }
78196
79197 if ($PendingBecause )
80198 {
81199 Set-ItResult - Pending - Because $PendingBecause
82200 }
83- $resource = Get-DscResource - Name $Name - Module $ModuleName
84- $resource | Should -Not - BeNullOrEmpty
85- $resource.Name | Should - Be $Name
201+
202+ $resources = @ (Get-DscResource - Name $name - Module $ModuleName )
203+ $resources | Should -Not - BeNullOrEmpty
204+ foreach ($resource in $resource )
205+ {
206+ $resource.Name | Should - Be $Name
207+ }
86208 }
87209
88- # Fails on all platforms
89210 it " should throw when resource is not found" {
90211 Set-ItResult - Pending - Because " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/17"
91212 {
@@ -99,19 +220,17 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
99220 BeforeAll {
100221 $origProgress = $global :ProgressPreference
101222 $global :ProgressPreference = ' SilentlyContinue'
102- Install-Module - Name XmlContentDsc - Force
223+ Install-ModuleIfMissing - Name XmlContentDsc - Force
103224 $classTestCases = @ (
104225 @ {
105226 TestCaseName = ' Good case'
106227 Name = ' XmlFileContentResource'
107228 ModuleName = ' XmlContentDsc'
108- PendingBecause = " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/19"
109229 }
110230 @ {
111231 TestCaseName = ' Module Name case mismatch'
112232 Name = ' XmlFileContentResource'
113233 ModuleName = ' xmlcontentdsc'
114- PendingBecause = ' https://github.com/PowerShell/PSDesiredStateConfiguration/issues/12'
115234 }
116235 @ {
117236 TestCaseName = ' Resource name case mismatch'
@@ -122,29 +241,27 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
122241 }
123242 AfterAll {
124243 $Global :ProgressPreference = $origProgress
125- Uninstall-Module - name XmlContentDsc - AllVersions
126244 }
127245
128- # Fix for most of thse are in https://github.com/PowerShell/PowerShell/pull/10350
129246 it " should be able to get class resource - <Name> from <ModuleName> - <TestCaseName>" - TestCases $classTestCases {
130247 param ($Name , $ModuleName , $PendingBecause )
131- if ($IsLinux -or $IsMacOs )
132- {
133- Set-ItResult - Pending - Because " Fix for most of these are in https://github.com/PowerShell/PowerShell/pull/10350"
134- }
135248
136249 if ($PendingBecause )
137250 {
138251 Set-ItResult - Pending - Because $PendingBecause
139252 }
253+
140254 $resource = Get-DscResource - Name $Name - Module $ModuleName
141255 $resource | Should -Not - BeNullOrEmpty
142256 $resource.Name | Should - Be $Name
143257 }
144258
145259 it " should be able to get class resource - <Name> - <TestCaseName>" - TestCases $classTestCases {
146260 param ($Name , $ModuleName , $PendingBecause )
147- Set-ItResult - Pending - Because " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/19"
261+ if ($IsWindows )
262+ {
263+ Set-ItResult - Pending - Because " https://github.com/PowerShell/PSDesiredStateConfiguration/issues/19"
264+ }
148265 if ($PendingBecause )
149266 {
150267 Set-ItResult - Pending - Because $PendingBecause
0 commit comments