Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Sep 30, 2023
1 parent dce8bc8 commit c6f6283
Show file tree
Hide file tree
Showing 2 changed files with 324 additions and 247 deletions.
33 changes: 20 additions & 13 deletions source/DSCResources/DSC_SqlAGListener/DSC_SqlAGListener.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ function Get-TargetResource

[Parameter(Mandatory = $true)]
[System.String]
$AvailabilityGroup
$AvailabilityGroup,

[Parameter()]
[System.Boolean]
$ProcessOnlyOnActiveNode
)

Write-Verbose -Message (
Expand Down Expand Up @@ -103,15 +107,16 @@ function Get-TargetResource
}

return @{
InstanceName = [System.String] $InstanceName
ServerName = [System.String] $ServerName
Name = [System.String] $Name
Ensure = [System.String] $ensure
AvailabilityGroup = [System.String] $AvailabilityGroup
IpAddress = [System.String[]] $ipAddress
Port = [System.UInt16] $port
DHCP = [System.Boolean] $dhcp
IsActiveNode = [System.Boolean] $isActiveNode
InstanceName = [System.String] $InstanceName
ServerName = [System.String] $ServerName
Name = [System.String] $Name
Ensure = [System.String] $ensure
AvailabilityGroup = [System.String] $AvailabilityGroup
IpAddress = [System.String[]] $ipAddress
Port = [System.UInt16] $port
DHCP = [System.Boolean] $dhcp
ProcessOnlyOnActiveNode = [System.Boolean] $ProcessOnlyOnActiveNode
IsActiveNode = [System.Boolean] $isActiveNode
}
}

Expand Down Expand Up @@ -432,7 +437,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification = 'The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down Expand Up @@ -495,11 +500,13 @@ function Test-TargetResource
If this is supposed to process only the active node, and this is not the
active node, don't bother evaluating the test.
#>
if ( $ProcessOnlyOnActiveNode -and -not $IsActiveNode )
if ($ProcessOnlyOnActiveNode -and -not $availabilityGroupListenerState.IsActiveNode)
{
# Use localization if the resource has been converted
New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $SQLInstanceName )
Write-Verbose -Message ('The node ''{0}'' is not actively hosting the instance ''{1}''. Exiting the test.' -f (Get-ComputerName), $InstanceName)

$result = $true

return $result
}

Expand Down
Loading

0 comments on commit c6f6283

Please sign in to comment.