Skip to content

Commit c5671bd

Browse files
committed
Further Unit Testing Improvements.
1 parent f780b8b commit c5671bd

File tree

3 files changed

+155
-54
lines changed

3 files changed

+155
-54
lines changed

source/DSCResources/DSC_xServiceResource/DSC_xServiceResource.psm1

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,10 @@ function Test-TargetResource
628628
New-InvalidArgumentException -ArgumentName 'BuiltInAccount / Credential / GroupManagedServiceAccount' -Message $errorMessage
629629
}
630630

631-
if(($PSBoundParameters.ContainsKey('Failure3Action') -and (-not $PSBoundParameters.ContainsKey('Failure2Action'))) -or
632-
($PSBoundParameters.ContainsKey('Failure2Action') -and (-not $PSBoundParameters.ContainsKey('Failure1Action')))
633-
)
631+
if ($PSBoundParameters.ContainsKey('FailureCommand') -and (-not (Test-HasRestartFailureAction -Collection $FailureActionsCollection)))
634632
{
635-
$errorMessage = $script:localizedData.FailureActionsMustBeSpecifiedInOrder
636-
New-InvalidArgumentException -ArgumentName 'Failure2Action / Failure3Action' -Message $errorMessage
633+
$errorMessage = $script:localizedData.MustSpecifyRestartFailureAction
634+
New-InvalidArgumentException -ArgumentName 'FailureCommand' -Message $errorMessage
637635
}
638636

639637
$serviceResource = Get-TargetResource -Name $Name
@@ -2458,3 +2456,25 @@ function Set-ServiceFailureActionProperty {
24582456
}
24592457
}
24602458
}
2459+
2460+
function Test-HasRestartFailureAction
2461+
{
2462+
[CmdletBinding()]
2463+
param (
2464+
[Parameter()]
2465+
[System.Object[]]
2466+
$Collection
2467+
)
2468+
2469+
process {
2470+
$hasRestartAction = $false
2471+
2472+
foreach ($action in $collection) {
2473+
if ($action.type -eq 'RUN_COMMAND') {
2474+
$hasRestartAction = $true
2475+
}
2476+
}
2477+
2478+
$hasRestartAction
2479+
}
2480+
}

source/DSCResources/DSC_xServiceResource/en-US/DSC_xServiceResource.strings.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ ConvertFrom-StringData @'
3737
CannotGetAccountAccessErrorMessage = Failed to get user policy rights.
3838
CannotSetAccountAccessErrorMessage = Failed to set user policy rights.
3939
CorruptDependency = Service '{0}' has a corrupt dependency. For more information, inspect the registry value at HKLM:\\SYSTEM\\CurrentControlSet\\Services\\{0}\\DependOnService.
40-
FailureActionsMustBeSpecifiedInOrder = Failure actions must be specified in order from 1 to 3.
40+
MustSpecifyRestartFailureAction = A failure command can only be specified if one of the failure actions is 'RUN_COMMAND'
4141
'@

0 commit comments

Comments
 (0)