Skip to content

Commit 6ed69fe

Browse files
committed
Fix review comments at r5
1 parent 808c77b commit 6ed69fe

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
## Unreleased
44

5-
- xComputer:
5+
- Computer:
66
- Fix for 'directory service is busy' error when joining a domain and renaming
77
a computer when JoinOU is specified - Fixes [Issue #221](https://github.com/PowerShell/ComputerManagementDsc/issues/221).
8-
- Added new resource
9-
- SmbShare (moved and improved from deprecated module xSmbShare).
8+
- Added new resource SmbShare
9+
- Moved and improved from deprecated module xSmbShare.
1010
- Changes to ComputerManagementDsc.Common
1111
- Updated Test-DscParameterState so it now can compare zero item
1212
collections (arrays).
13+
- Changes to WindowsEventLog
14+
- Minor style guideline cleanup.
1315

1416
## 6.4.0.0
1517

DSCResources/MSFT_SmbShare/MSFT_SmbShare.psm1

+5-5
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function Set-TargetResource
270270
$_ -in ('ChangeAccess','ReadAccess','FullAccess','NoAccess','Ensure','Path')
271271
}
272272

273-
$parametersToRemove | ForEach-Object {
273+
$parametersToRemove | ForEach-Object -Process {
274274
$smbShareParameters.Remove($_)
275275
}
276276

@@ -672,7 +672,7 @@ function Add-SmbShareAccessPermission
672672
$accessRight = 'Change'
673673

674674
# Add new accounts that should have change permission.
675-
$newAccountsToHaveChangeAccess | ForEach-Object {
675+
$newAccountsToHaveChangeAccess | ForEach-Object -Process {
676676
Write-Verbose -Message ($script:localizedData.GrantAccess -f $accessRight, $_, $Name)
677677

678678
Grant-SmbShareAccess -Name $Name -AccountName $_ -AccessRight $accessRight -Force -ErrorAction 'Stop'
@@ -697,7 +697,7 @@ function Add-SmbShareAccessPermission
697697
$accessRight = 'Read'
698698

699699
# Add new accounts that should have read permission.
700-
$newAccountsToHaveReadAccess | ForEach-Object {
700+
$newAccountsToHaveReadAccess | ForEach-Object -Process {
701701
Write-Verbose -Message ($script:localizedData.GrantAccess -f $accessRight, $_, $Name)
702702

703703
Grant-SmbShareAccess -Name $Name -AccountName $_ -AccessRight $accessRight -Force -ErrorAction 'Stop'
@@ -722,7 +722,7 @@ function Add-SmbShareAccessPermission
722722
$accessRight = 'Full'
723723

724724
# Add new accounts that should have full permission.
725-
$newAccountsToHaveFullAccess | ForEach-Object {
725+
$newAccountsToHaveFullAccess | ForEach-Object -Process {
726726
Write-Verbose -Message ($script:localizedData.GrantAccess -f $accessRight, $_, $Name)
727727

728728
Grant-SmbShareAccess -Name $Name -AccountName $_ -AccessRight $accessRight -Force -ErrorAction 'Stop'
@@ -745,7 +745,7 @@ function Add-SmbShareAccessPermission
745745
}
746746

747747
# Add new accounts that should be denied permission.
748-
$newAccountsToHaveNoAccess | ForEach-Object {
748+
$newAccountsToHaveNoAccess | ForEach-Object -Process {
749749
Write-Verbose -Message ($script:localizedData.DenyAccess -f $_, $Name)
750750

751751
Block-SmbShareAccess -Name $Name -AccountName $_ -Force -ErrorAction 'Stop'

DSCResources/MSFT_WindowsEventLog/MSFT_WindowsEventLog.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function Set-TargetResource
177177

178178
if ($PSBoundParameters.ContainsKey('LogRetentionDays'))
179179
{
180-
if ($LogMode -eq 'AutoBackup' -and (Get-EventLog -List | Where-Object {$_.Log -like $LogName}))
180+
if ($LogMode -eq 'AutoBackup' -and (Get-EventLog -List | Where-Object -FilterScript {$_.Log -like $LogName}))
181181
{
182182
$matchingEventLog = Get-EventLog -List | Where-Object -FilterScript {
183183
$_.Log -eq $LogName

Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function Remove-CommonParameter
3333
$commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters
3434
$commonParameters += [System.Management.Automation.PSCmdlet]::OptionalCommonParameters
3535

36-
$Hashtable.Keys | Where-Object { $_ -in $commonParameters } | ForEach-Object {
36+
$Hashtable.Keys | Where-Object -FilterScript { $_ -in $commonParameters } | ForEach-Object -Process {
3737
$inputClone.Remove($_)
3838
}
3939

Tests/Integration/MSFT_ScheduledTask.Integration.Tests.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ try
177177
}
178178

179179
It 'Should have set the resource and all the parameters should match' {
180-
$current = Get-DscConfiguration | Where-Object {$_.ConfigurationName -eq $currentConfig}
180+
$current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $currentConfig}
181181
$current.TaskName | Should -Be 'Test task once cross timezone'
182182
$current.TaskPath | Should -Be '\ComputerManagementDsc\'
183183
$current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
@@ -229,7 +229,7 @@ try
229229
$expectedStartTime = '2018-10-01T01:00:00'
230230

231231
It 'Should have set the resource and all the parameters should match' {
232-
$current = Get-DscConfiguration | Where-Object {$_.ConfigurationName -eq $currentConfig}
232+
$current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $currentConfig}
233233
$current.TaskName | Should -Be 'Test task sync across time zone disabled'
234234
$current.TaskPath | Should -Be '\ComputerManagementDsc\'
235235
$current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
@@ -276,7 +276,7 @@ try
276276
$expectedStartTime = '2018-10-01T01:00:00' + (Get-Date -Format 'zzz')
277277

278278
It 'Should have set the resource and all the parameters should match' {
279-
$current = Get-DscConfiguration | Where-Object {$_.ConfigurationName -eq $currentConfig}
279+
$current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $currentConfig}
280280
$current.TaskName | Should -Be 'Test task sync across time zone enabled'
281281
$current.TaskPath | Should -Be '\ComputerManagementDsc\'
282282
$current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'

Tests/Unit/MSFT_SmbShare.Tests.ps1

+17-24
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ try
120120
}
121121
}
122122

123-
It 'Should mock call to Get-SmbShare and return membership' {
123+
It 'Should return the correct access memberships' {
124124
$getTargetResourceResult = Get-TargetResource @testParameters
125125

126126
$getTargetResourceResult.ChangeAccess | Should -HaveCount 1
@@ -135,15 +135,8 @@ try
135135

136136
$getTargetResourceResult.NoAccess | Should -HaveCount 1
137137
$getTargetResourceResult.NoAccess[0] | Should -BeIn $mockNoPermissionUserName
138-
}
139138

140-
It 'Should call the mock function Get-SmbShare' {
141-
$getTargetResourceResult = Get-TargetResource @testParameters
142139
Assert-MockCalled Get-SmbShare -Exactly -Times 1 -Scope It
143-
}
144-
145-
It 'Should Call the mock function Get-SmbShareAccess' {
146-
$getTargetResourceResult = Get-TargetResource @testParameters
147140
Assert-MockCalled Get-SmbShareAccess -Exactly -Times 1 -Scope It
148141
}
149142
}
@@ -179,8 +172,9 @@ try
179172
$getTargetResourceResult.ReadAccess | Should -HaveCount 0
180173
$getTargetResourceResult.FullAccess | Should -HaveCount 0
181174
$getTargetResourceResult.NoAccess | Should -HaveCount 0
182-
}
183175

176+
Assert-MockCalled Get-SmbShare -Exactly -Times 1 -Scope It
177+
}
184178
}
185179
}
186180

@@ -220,7 +214,7 @@ try
220214
}
221215

222216
Context 'When no access permission is given' {
223-
It 'Should call the correct mocks' {
217+
It 'Should throw the correct error' {
224218
$setTargetResourceParameters = @{
225219
Name = $mockShareName
226220
Path = 'TestDrive:\Temp'
@@ -347,13 +341,12 @@ try
347341
Assert-MockCalled Remove-SmbShare -Exactly -Times 0 -Scope It
348342
}
349343
}
350-
351344
}
352345
}
353346

354347
Describe 'MSFT_SmbShare\Test-TargetResource' -Tag 'Test' {
355348
Context 'When the system is not in the desired state' {
356-
Context 'When no members in provided in neither access permission collection' {
349+
Context 'When no member are provided in any of the access permission collections' {
357350
BeforeAll {
358351
$testTargetResourceParameters = @{
359352
Name = $mockShareName
@@ -680,7 +673,7 @@ try
680673
}
681674
}
682675

683-
It 'Should call the correct mock' {
676+
It 'Should not throw an error and call the correct mocks' {
684677
{ Add-SmbShareAccessPermission @addSmbShareAccessPermissionParameters } | Should -Not -Throw
685678

686679
<#
@@ -706,7 +699,7 @@ try
706699
}
707700
}
708701

709-
It 'Should call the correct mock' {
702+
It 'Should not throw an error and call the correct mocks' {
710703
{ Add-SmbShareAccessPermission @addSmbShareAccessPermissionParameters } | Should -Not -Throw
711704

712705
<#
@@ -732,7 +725,7 @@ try
732725
}
733726
}
734727

735-
It 'Should call the correct mock' {
728+
It 'Should not throw an error and call the correct mocks' {
736729
{ Add-SmbShareAccessPermission @addSmbShareAccessPermissionParameters } | Should -Not -Throw
737730

738731
<#
@@ -764,7 +757,7 @@ try
764757
}
765758
}
766759

767-
It 'Should call the correct mock' {
760+
It 'Should not throw an error and call the correct mocks' {
768761
{ Add-SmbShareAccessPermission @addSmbShareAccessPermissionParameters } | Should -Not -Throw
769762

770763
<#
@@ -809,7 +802,7 @@ try
809802
}
810803
}
811804

812-
It 'Should call the correct mock' {
805+
It 'Should not throw an error and call the correct mocks' {
813806
{ Add-SmbShareAccessPermission @removeSmbShareAccessPermissionParameters } | Should -Not -Throw
814807

815808
<#
@@ -860,7 +853,7 @@ try
860853
}
861854
}
862855

863-
It 'Should call the correct mock' {
856+
It 'Should not throw an error and call the correct mocks' {
864857
{ Remove-SmbShareAccessPermission @removeSmbShareAccessPermissionParameters } | Should -Not -Throw
865858

866859
<#
@@ -887,7 +880,7 @@ try
887880
}
888881
}
889882

890-
It 'Should call the correct mocks' {
883+
It 'Should not throw an error and call the correct mocks' {
891884
{ Remove-SmbShareAccessPermission @removeSmbShareAccessPermissionParameters } | Should -Not -Throw
892885

893886
<#
@@ -918,7 +911,7 @@ try
918911
}
919912
}
920913

921-
It 'Should call the correct mock' {
914+
It 'Should not throw an error and call the correct mocks' {
922915
{ Remove-SmbShareAccessPermission @removeSmbShareAccessPermissionParameters } | Should -Not -Throw
923916

924917
<#
@@ -944,7 +937,7 @@ try
944937
}
945938
}
946939

947-
It 'Should call the correct mock' {
940+
It 'Should not throw an error and call the correct mocks' {
948941
{ Remove-SmbShareAccessPermission @removeSmbShareAccessPermissionParameters } | Should -Not -Throw
949942

950943
<#
@@ -972,7 +965,7 @@ try
972965
}
973966
}
974967

975-
It 'Should call the correct mock' {
968+
It 'Should not throw an error and call the correct mocks' {
976969
{ Remove-SmbShareAccessPermission @removeSmbShareAccessPermissionParameters } | Should -Not -Throw
977970

978971
Assert-MockCalled -CommandName Revoke-SmbShareAccess -Exactly -Times 4 -Scope 'It'
@@ -1015,7 +1008,7 @@ try
10151008
}
10161009
}
10171010

1018-
It 'Should call the correct mock' {
1011+
It 'Should not throw an error and call the correct mocks' {
10191012
{ Remove-SmbShareAccessPermission @removeSmbShareAccessPermissionParameters } | Should -Not -Throw
10201013

10211014
<#
@@ -1092,7 +1085,7 @@ try
10921085
}
10931086
}
10941087

1095-
Context 'When providing no member in either of the access permission collections' {
1088+
Context 'When not providing any members in any of the access permission collections' {
10961089
It 'Should throw the correct error' {
10971090
# We must using splatting to test 'ValueFromRemainingArguments' parameter.
10981091
$assertAccessPermissionParameters = @{

0 commit comments

Comments
 (0)