Skip to content

Commit

Permalink
SqlAGReplica: Converted unit tests to Pester 5 (#1820)
Browse files Browse the repository at this point in the history
- SqlAgReplica
  - Converted unit test to Pester 5.
  - No longer tries to enforce EndpointHostName when it is not part of the
    configuration (issue #1821).
  - Now `Get-TargetResource` always returns values for the properties `Name`
    and `AvailabilityGroupName` (issue #1822).
  - Now `Test-TargetResource` no longer test properties that cannot
    be enforced (issue #1822).
  • Loading branch information
johlju authored Dec 16, 2022
1 parent d5692e2 commit 92612af
Show file tree
Hide file tree
Showing 3 changed files with 1,321 additions and 1,119 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
running in Azure DevOps.
- `Install-SqlServerDsc`
- No longer throws an exception when parameter `AgtSvcAccount` is not specified.
- SqlAgReplica
- Converted unit test to Pester 5.

### Fixed

- SqlServerDsc
- Localized strings file `en-US/SqlServerDsc.strings.psd1` no longer
referencing the wrong module in a comment.
- SqlAGReplica
- No longer tries to enforce EndpointHostName when it is not part of the
configuration ([issue #1821](https://github.com/dsccommunity/SqlServerDsc/issues/1821)).
- Now `Get-TargetResource` always returns values for the properties `Name`
and `AvailabilityGroupName` ([issue #1822](https://github.com/dsccommunity/SqlServerDsc/issues/1822)).
- Now `Test-TargetResource` no longer test properties that cannot
be enforced ([issue #1822](https://github.com/dsccommunity/SqlServerDsc/issues/1822)).

## [16.0.0] - 2022-09-09

Expand Down
20 changes: 3 additions & 17 deletions source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function Get-TargetResource
# Create the return object
$alwaysOnAvailabilityGroupReplicaResource = @{
Ensure = 'Absent'
Name = ''
AvailabilityGroupName = ''
Name = $Name
AvailabilityGroupName = $AvailabilityGroupName
AvailabilityMode = ''
BackupPriority = ''
ConnectionModeInPrimaryRole = ''
Expand All @@ -87,17 +87,13 @@ function Get-TargetResource

if ( $availabilityGroup )
{
# Add the Availability Group name to the results
$alwaysOnAvailabilityGroupReplicaResource.AvailabilityGroupName = $availabilityGroup.Name

# Try to find the replica
$availabilityGroupReplica = $availabilityGroup.AvailabilityReplicas[$Name]

if ( $availabilityGroupReplica )
{
# Add the Availability Group Replica properties to the results
$alwaysOnAvailabilityGroupReplicaResource.Ensure = 'Present'
$alwaysOnAvailabilityGroupReplicaResource.Name = $availabilityGroupReplica.Name
$alwaysOnAvailabilityGroupReplicaResource.AvailabilityMode = $availabilityGroupReplica.AvailabilityMode
$alwaysOnAvailabilityGroupReplicaResource.BackupPriority = $availabilityGroupReplica.BackupPriority
$alwaysOnAvailabilityGroupReplicaResource.ConnectionModeInPrimaryRole = $availabilityGroupReplica.ConnectionModeInPrimaryRole
Expand Down Expand Up @@ -672,11 +668,6 @@ function Test-TargetResource
'Present'
{
$parametersToCheck = @(
'Name',
'AvailabilityGroupName',
'ServerName',
'InstanceName',
'Ensure',
'AvailabilityMode',
'BackupPriority',
'ConnectionModeInPrimaryRole',
Expand Down Expand Up @@ -721,13 +712,8 @@ function Test-TargetResource
# Get the Endpoint URL properties
$currentEndpointProtocol, $currentEndpointHostName, $currentEndpointPort = $getTargetResourceResult.EndpointUrl.Replace('//', '').Split(':')

if ( -not $EndpointHostName )
{
$EndpointHostName = $getTargetResourceResult.EndpointHostName
}

# Verify the hostname in the endpoint URL is correct
if ( $EndpointHostName -ne $currentEndpointHostName )
if ( $PSBoundParameters.ContainsKey('EndpointHostName') -and $EndpointHostName -ne $currentEndpointHostName )
{
Write-Verbose -Message (
$script:localizedData.ParameterNotInDesiredState -f 'EndpointHostName', $EndpointHostName, $currentEndpointHostName
Expand Down
Loading

0 comments on commit 92612af

Please sign in to comment.