Skip to content

Commit

Permalink
Merge pull request #98 from johlju/additional-tests-for-alwayson
Browse files Browse the repository at this point in the history
Additional tests, and some fixes, related to AlwaysOn
  • Loading branch information
mbreakey3 authored Aug 17, 2016
2 parents da15621 + 2e05d05 commit bcc39fb
Show file tree
Hide file tree
Showing 10 changed files with 6,030 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Get-TargetResource

$presentIpAddress = $listener.AvailabilityGroupListenerIPAddresses

$dhcp = [bool]( $presentIpAddress | Select-Object -first 1 IsDHCP )
$dhcp = [bool]( $presentIpAddress | Select-Object -First 1 -ExpandProperty IsDHCP )

$ipAddress = @()
foreach( $currentIpAddress in $presentIpAddress ) {
Expand Down Expand Up @@ -169,6 +169,10 @@ function Set-TargetResource
throw New-TerminatingError -ErrorType AvailabilityGroupListenerIPChangeError -FormatArgs @($($IpAddress -join ', '),$($listenerState.IpAddress -join ', ')) -ErrorCategory InvalidOperation
}
}

if( $($PSBoundParameters.ContainsKey('DHCP')) -and $listenerState.DHCP -ne $DHCP ) {
throw New-TerminatingError -ErrorType AvailabilityGroupListenerDHCPChangeError -FormatArgs @( $DHCP, $($listenerState.DHCP) ) -ErrorCategory InvalidOperation
}

if( $listenerState.Port -ne $Port -or -not $ipAddressEqual ) {
New-VerboseMessage -Message "Listener differ in configuration."
Expand All @@ -193,7 +197,7 @@ function Set-TargetResource
$newIpAddress = @()

foreach( $currentIpAddress in $IpAddress ) {
if( -not $listenerState.IpAddress -contains $currentIpAddress ) {
if( -not ( $listenerState.IpAddress -contains $currentIpAddress ) ) {
$newIpAddress += $currentIpAddress
}
}
Expand Down Expand Up @@ -274,9 +278,21 @@ function Test-TargetResource
}

[System.Boolean] $result = $false
if( ( $Ensure -eq "" -or ( $Ensure -ne "" -and $listenerState.Ensure -eq $Ensure) ) -and ($Port -eq "" -or $listenerState.Port -eq $Port) -and $ipAddressEqual ) {
$result = $true
if( $listenerState.Ensure -eq $Ensure) {
if( $Ensure -eq 'Absent' ) {
$result = $true
}
}

if( -not $($PSBoundParameters.ContainsKey('Ensure')) -or $Ensure -eq "Present" ) {
if( ( $Port -eq "" -or $listenerState.Port -eq $Port) -and
$ipAddressEqual -and
( -not $($PSBoundParameters.ContainsKey('DHCP')) -or $listenerState.DHCP -eq $DHCP ) )
{
$result = $true
}
}

} else {
throw New-TerminatingError -ErrorType UnexpectedErrorFromGet -ErrorCategory InvalidResult
}
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
### Unreleased
* Added resources
- xSQLServerReplication
* Added tests for resources
- xSQLServerPermission
- xSQLServerEndpointState
- xSQLServerEndpointPermission
- xSQLServerAvailabilityGroupListener
* Fixes in xSQLServerAvailabilityGroupListener
- In one case the Get-method did not report that DHCP was configured.
- Now the resource will throw 'Not supported' when IP is changed between Static and DHCP.
- Fixed an issue where sometimes the listener wasn't removed.
- Fixed the issue when trying to add a static IP to a listener was ignored.

### 1.8.0.0
* Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey.
Expand Down
49 changes: 33 additions & 16 deletions Tests/Unit/Stubs/SMO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@

namespace Microsoft.SqlServer.Management.Smo
{
public class Globals
{
// Static property that is switched on or off by tests if data should be mocked (true) or not (false).
public static bool GenerateMockData = false;
}

// Typename: Microsoft.SqlServer.Management.Smo.ObjectPermissionSet
// BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase
// Used by:
// xSQLServerEndpointPermission.Tests.ps1
public class ObjectPermissionSet
{
public ObjectPermissionSet(){}

public ObjectPermissionSet(
bool connect )
{
this.Connect = connect;
}

public bool Connect = false;
}

// TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionSet
// BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase
// Used by:
// xSQLServerPermission
// xSQLServerPermission.Tests.ps1
public class ServerPermissionSet
{
public ServerPermissionSet(){}
Expand All @@ -32,7 +55,7 @@ public ServerPermissionSet(
// TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionInfo
// BaseType: Microsoft.SqlServer.Management.Smo.PermissionInfo
// Used by:
// xSQLServerPermission
// xSQLServerPermission.Tests.ps1
public class ServerPermissionInfo
{
public ServerPermissionInfo()
Expand All @@ -54,33 +77,23 @@ public ServerPermissionInfo(
// TypeName: Microsoft.SqlServer.Management.Smo.Server
// BaseType: Microsoft.SqlServer.Management.Smo.SqlSmoObject
// Used by:
// xSQLServerPermission
// xSQLServerPermission.Tests.ps1
public class Server
{
private bool _generateMockData = false;

public string MockGranteeName;

public string Name;
public string DisplayName;
public string InstanceName;
public bool IsHadrEnabled = false;

public Server()
{
_generateMockData = false;
}

public Server( bool generateMockData )
{
this._generateMockData = generateMockData;
}
public Server(){}

public Microsoft.SqlServer.Management.Smo.ServerPermissionInfo[] EnumServerPermissions( string principal, Microsoft.SqlServer.Management.Smo.ServerPermissionSet permissionSetQuery )
{
List<Microsoft.SqlServer.Management.Smo.ServerPermissionInfo> listOfServerPermissionInfo = new List<Microsoft.SqlServer.Management.Smo.ServerPermissionInfo>();

if( this._generateMockData ) {
if( Globals.GenerateMockData ) {
Microsoft.SqlServer.Management.Smo.ServerPermissionSet[] permissionSet = {
new Microsoft.SqlServer.Management.Smo.ServerPermissionSet( true, false, false, false ),
new Microsoft.SqlServer.Management.Smo.ServerPermissionSet( false, true, false, false ),
Expand Down Expand Up @@ -108,7 +121,11 @@ public void Grant( Microsoft.SqlServer.Management.Smo.ServerPermissionSet permis

public void Revoke( Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string granteeName )
{

if( granteeName != this.MockGranteeName )
{
string errorMessage = "Expected to get granteeName == '" + this.MockGranteeName + "'. But got '" + granteeName + "'";
throw new System.ArgumentException(errorMessage, "granteeName");
}
}
}
}
Loading

0 comments on commit bcc39fb

Please sign in to comment.