Skip to content

Commit

Permalink
Further Unit Testing Improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomNoun7 committed Apr 17, 2020
1 parent f780b8b commit c5671bd
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 54 deletions.
30 changes: 25 additions & 5 deletions source/DSCResources/DSC_xServiceResource/DSC_xServiceResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,10 @@ function Test-TargetResource
New-InvalidArgumentException -ArgumentName 'BuiltInAccount / Credential / GroupManagedServiceAccount' -Message $errorMessage
}

if(($PSBoundParameters.ContainsKey('Failure3Action') -and (-not $PSBoundParameters.ContainsKey('Failure2Action'))) -or
($PSBoundParameters.ContainsKey('Failure2Action') -and (-not $PSBoundParameters.ContainsKey('Failure1Action')))
)
if ($PSBoundParameters.ContainsKey('FailureCommand') -and (-not (Test-HasRestartFailureAction -Collection $FailureActionsCollection)))
{
$errorMessage = $script:localizedData.FailureActionsMustBeSpecifiedInOrder
New-InvalidArgumentException -ArgumentName 'Failure2Action / Failure3Action' -Message $errorMessage
$errorMessage = $script:localizedData.MustSpecifyRestartFailureAction
New-InvalidArgumentException -ArgumentName 'FailureCommand' -Message $errorMessage
}

$serviceResource = Get-TargetResource -Name $Name
Expand Down Expand Up @@ -2458,3 +2456,25 @@ function Set-ServiceFailureActionProperty {
}
}
}

function Test-HasRestartFailureAction
{
[CmdletBinding()]
param (
[Parameter()]
[System.Object[]]
$Collection
)

process {
$hasRestartAction = $false

foreach ($action in $collection) {
if ($action.type -eq 'RUN_COMMAND') {
$hasRestartAction = $true
}
}

$hasRestartAction
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ ConvertFrom-StringData @'
CannotGetAccountAccessErrorMessage = Failed to get user policy rights.
CannotSetAccountAccessErrorMessage = Failed to set user policy rights.
CorruptDependency = Service '{0}' has a corrupt dependency. For more information, inspect the registry value at HKLM:\\SYSTEM\\CurrentControlSet\\Services\\{0}\\DependOnService.
FailureActionsMustBeSpecifiedInOrder = Failure actions must be specified in order from 1 to 3.
MustSpecifyRestartFailureAction = A failure command can only be specified if one of the failure actions is 'RUN_COMMAND'
'@
Loading

0 comments on commit c5671bd

Please sign in to comment.