Skip to content

Commit e92798d

Browse files
authored
Added wildcard support in Products parameter of UpdateServicesServer resource (#71)
1 parent 6c087d0 commit e92798d

File tree

7 files changed

+484
-142
lines changed

7 files changed

+484
-142
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
- Added TestKitchen files for integration tests
1919
- Added requiredmodules Sampler.GitHubTasks, powershell-yaml
20+
- Added wildcard support in Products parameter of UpdatesServicesServer resource.
21+
(issue #13)
2022

21-
### Fix
23+
### Fixed
2224

2325
- Fix deploy job in AzurePipeline, Added Sampler.GithubTasks in build.yaml
26+
- Fix issue #61 and #67, with add a foreach loop when `Set-TargetRessource` found
27+
multiple products dor the same `Title`.
28+
- Fix issue #58 and #66, with removed `-ErrorRecord` parameter on `New-InvalidResultException`
29+
because `$_` not contain an exception.
2430

2531
## [1.2.0] - 2020-05-18
2632

Tests/Helpers/ImitateUpdateServicesModule.psm1

Lines changed: 148 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
1-
function Get-WsusServer {
1+
function Get-WsusServerTemplate
2+
{
23
$WsusServer = [pscustomobject] @{
34
Name = 'ServerName'
45
}
56

67
$ApprovalRule = [scriptblock]{
78
$ApprovalRule = [pscustomobject]@{
8-
Name = 'ServerName'
9-
Enabled = $true
9+
Name = 'ServerName'
10+
Enabled = $true
1011
}
11-
12+
1213
$ApprovalRule | Add-Member -MemberType ScriptMethod -Name GetUpdateClassifications -Value {
1314
$UpdateClassification = [pscustomobject]@{
14-
Name = 'Update Classification'
15-
ID = [pscustomobject]@{
16-
GUID = '00000000-0000-0000-0000-0000testguid'
17-
}
15+
Name = 'Update Classification'
16+
ID = [pscustomobject]@{
17+
GUID = '00000000-0000-0000-0000-0000testguid'
18+
}
1819
}
20+
1921
return $UpdateClassification
2022
}
2123

2224
$ApprovalRule | Add-Member -MemberType ScriptMethod -Name GetCategories -Value {
2325
$Products = [pscustomobject]@{
2426
Title = 'Product'
2527
}
28+
2629
$Products | Add-Member -MemberType ScriptMethod -Name Add -Value {}
30+
2731
return $Products
2832
}
2933

3034
$ApprovalRule | Add-Member -MemberType ScriptMethod -Name GetComputerTargetGroups -Value {
3135
$ComputerTargetGroups = [pscustomobject]@{
3236
Name = 'Computer Target Group'
3337
}
38+
3439
$ComputerTargetGroups | Add-Member -MemberType ScriptMethod -Name Add -Value {}
40+
3541
return $ComputerTargetGroups
3642
}
3743

@@ -51,33 +57,41 @@ function Get-WsusServer {
5157
$WsusServer | Add-Member -MemberType ScriptMethod -Name CreateInstallApprovalRule -Value $ApprovalRule
5258

5359
$WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateClassification -Value {}
54-
60+
5561
$WsusServer | Add-Member -MemberType ScriptMethod -Name GetComputerTargetGroups -Value {}
5662

5763
$WsusServer | Add-Member -MemberType ScriptMethod -Name DeleteInstallApprovalRule -Value {}
58-
64+
5965
$WsusServer | Add-Member -MemberType ScriptMethod -Name GetSubscription -Value {
6066
$Subscription = [pscustomobject]@{
6167
SynchronizeAutomaticallyTimeOfDay = '04:00:00'
6268
NumberOfSynchronizationsPerDay = 24
6369
SynchronizeAutomatically = $true
6470
}
71+
6572
$Subscription | Add-Member -MemberType ScriptMethod -Name StartSynchronization -Value {}
6673
$Subscription | Add-Member -MemberType ScriptMethod -Name GetUpdateClassifications -Value {
6774
$UpdateClassification = [pscustomobject]@{
68-
Name = 'Update Classification'
69-
ID = [pscustomobject]@{
70-
GUID = '00000000-0000-0000-0000-0000testguid'
71-
}
75+
Name = 'Update Classification'
76+
ID = [pscustomobject]@{
77+
GUID = '00000000-0000-0000-0000-0000testguid'
78+
}
7279
}
80+
7381
return $UpdateClassification
7482
}
83+
7584
$Subscription | Add-Member -MemberType ScriptMethod -Name GetUpdateCategories -Value {
7685
$Categories = [pscustomobject]@{
77-
Title = 'Category'
86+
Title = 'Windows'
87+
},
88+
[pscustomobject]@{
89+
Title = 'Office'
7890
}
91+
7992
return $Categories
8093
}
94+
8195
return $Subscription
8296
}
8397

@@ -93,37 +107,150 @@ function Get-WsusServer {
93107
AllUpdateLanguagesEnabled = $true
94108
}
95109
$Configuration | Add-Member -MemberType ScriptMethod -Name GetEnabledUpdateLanguages -Value {}
96-
return $Configuration
110+
111+
return $Configuration
97112
}
98113

99114
$WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateClassifications -Value {
100115
$UpdateClassification = [pscustomobject]@{
116+
Name = 'Update Classification'
117+
ID = [pscustomobject]@{
118+
GUID = '00000000-0000-0000-0000-0000testguid'
119+
}
120+
}
121+
122+
return $UpdateClassification
123+
}
124+
125+
$WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateCategories -Value {
126+
$Categories = [pscustomobject]@{
127+
Title = 'Windows'
128+
},
129+
[pscustomobject]@{
130+
Title = 'Office'
131+
},
132+
[pscustomobject]@{
133+
Title = 'Windows Server 2003'
134+
},
135+
[pscustomobject]@{
136+
Title = 'Windows Server 2008'
137+
},
138+
[pscustomobject]@{
139+
Title = 'Windows Server 2008R2'
140+
},
141+
[pscustomobject]@{
142+
Title = 'Windows Server 2012'
143+
},
144+
[pscustomobject]@{
145+
Title = 'Windows Server 2016'
146+
},
147+
[pscustomobject]@{
148+
Title = 'Windows Server 2019'
149+
}
150+
151+
return $Categories
152+
}
153+
154+
return $WsusServer
155+
}
156+
157+
function Get-WsusServer
158+
{
159+
return $(Get-WsusServerTemplate)
160+
}
161+
162+
function Get-WsusServerMockWildCardPrdt
163+
{
164+
$wsusServer = Get-WsusServerTemplate
165+
166+
# Override GetSubscription method
167+
$WsusServer | Add-Member -Force -MemberType ScriptMethod -Name GetSubscription -Value {
168+
$Subscription = [pscustomobject]@{
169+
SynchronizeAutomaticallyTimeOfDay = '04:00:00'
170+
NumberOfSynchronizationsPerDay = 24
171+
SynchronizeAutomatically = $true
172+
}
173+
174+
$Subscription | Add-Member -MemberType ScriptMethod -Name StartSynchronization -Value {}
175+
$Subscription | Add-Member -MemberType ScriptMethod -Name GetUpdateClassifications -Value {
176+
$UpdateClassification = [pscustomobject]@{
101177
Name = 'Update Classification'
102178
ID = [pscustomobject]@{
103179
GUID = '00000000-0000-0000-0000-0000testguid'
104180
}
181+
}
182+
183+
return $UpdateClassification
105184
}
106-
return $UpdateClassification
185+
186+
$Subscription | Add-Member -Force -MemberType ScriptMethod -Name GetUpdateCategories -Value {
187+
$Categories = [pscustomobject]@{
188+
Title = 'Windows Server 2003'
189+
},
190+
[pscustomobject]@{
191+
Title = 'Windows Server 2008'
192+
},
193+
[pscustomobject]@{
194+
Title = 'Windows Server 2008R2'
195+
},
196+
[pscustomobject]@{
197+
Title = 'Windows Server 2012'
198+
},
199+
[pscustomobject]@{
200+
Title = 'Windows Server 2016'
201+
},
202+
[pscustomobject]@{
203+
Title = 'Windows Server 2019'
204+
}
205+
206+
return $Categories
207+
}
208+
209+
return $Subscription
107210
}
108211

109-
$WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateCategories -Value {
212+
# Override GetUpdateCategories method
213+
$WsusServer | Add-Member -Force -MemberType ScriptMethod -Name GetUpdateCategories -Value {
110214
$Categories = [pscustomobject]@{
111-
Title = 'Category'
215+
Title = 'Windows'
216+
},
217+
[pscustomobject]@{
218+
Title = 'Office'
219+
},
220+
[pscustomobject]@{
221+
Title = 'Windows Server 2003'
222+
},
223+
[pscustomobject]@{
224+
Title = 'Windows Server 2008'
225+
},
226+
[pscustomobject]@{
227+
Title = 'Windows Server 2008R2'
228+
},
229+
[pscustomobject]@{
230+
Title = 'Windows Server 2012'
231+
},
232+
[pscustomobject]@{
233+
Title = 'Windows Server 2016'
234+
},
235+
[pscustomobject]@{
236+
Title = 'Windows Server 2019'
112237
}
238+
113239
return $Categories
114240
}
115241

116242
return $WsusServer
117243
}
118-
119-
function Get-WsusClassification {
244+
function Get-WsusClassification
245+
{
120246
$WsusClassification = [pscustomobject]@{
121247
Classification = [pscustomobject]@{
122248
ID = [pscustomobject]@{
123249
Guid = '00000000-0000-0000-0000-0000testguid'
124250
}
125251
}
126252
}
253+
127254
return $WsusClassification
128255
}
129256

Tests/Integration/WildcardInProduct/updateservicesDsc_WilcardInProduct.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Describe "Basic tests" {
2020
}
2121

2222
It "Should product are correctly configured" {
23-
$AllProductsServer = $script:wuServer.GetUpdateCategories().Title | Where-Object {$_ -like 'Windows Server *'}
23+
$AllProductsServer = $script:wuServer.GetUpdateCategories().Title | Where-Object {$_ -like 'Windows Server*'}
2424

2525
($AllProductsServer | Measure-Object).Count | Should -Be ($script:wuServer.GetSubscription().GetUpdateCategories().Title | Measure-Object ).Count
2626

Tests/Integration/defaultProducts/updateservicesDsc_defaultProducts.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Describe "Basic tests" {
2020
}
2121

2222
It "Should product are correctly configured" {
23-
$AllProductsServer = $script:wuServer.GetUpdateCategories().Title | Where-Object {$_ -like 'Windows Server*'}
23+
$AllProductsServer = $script:wuServer.GetUpdateCategories().Title | Where-Object {$_ -in @('Office','Windows')}
2424

2525
($AllProductsServer | Measure-Object).Count | Should -Be ($script:wuServer.GetSubscription().GetUpdateCategories().Title | Measure-Object ).Count
2626

0 commit comments

Comments
 (0)