Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional tests, and some fixes, related to AlwaysOn #98

Merged
merged 26 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d1c7803
Changes to the test for xSQLServerPermission
johlju Aug 5, 2016
af47472
Added test for xSQLServerEndpointState
johlju Aug 5, 2016
e78c304
Cleanup of test for xSQLServerEndpointState
johlju Aug 5, 2016
dea4051
Changed test for xSQLServerEndpointState
johlju Aug 6, 2016
90212ab
Added test for xSQLServerEndpointPermission
johlju Aug 7, 2016
683bcb7
Changed readme.md
johlju Aug 7, 2016
2fddb0b
Fixed bug in xSQLServerAvailabilityGroupListener
johlju Aug 7, 2016
ecdac6e
Bug fixed in xSQLServerAvailibilityGroupListener
johlju Aug 7, 2016
5e18c15
Added test for xSQLServerAvailabilityGroupListener
johlju Aug 8, 2016
0927272
Change test xSQLServerAvailabilityGroupListener
johlju Aug 8, 2016
df71fda
Fixed issue #95
johlju Aug 8, 2016
cc95942
Updated readme.md
johlju Aug 8, 2016
fb38dee
Added stub for SQLServer module
johlju Aug 9, 2016
966b31d
Added SQLPS Stub module
johlju Aug 9, 2016
9f8960b
Improved throwing from stub functions
johlju Aug 12, 2016
9b6e8b7
Fixes issue #102
johlju Aug 12, 2016
7b257d9
Changes to tests to use the stub file for SQLPS
johlju Aug 12, 2016
f9a9744
Resolved merge conflicts
johlju Aug 12, 2016
58869dd
Formating was wrong in the stub files
johlju Aug 12, 2016
89cd0fb
Suppressing PSAvoidUsingUserNameAndPassWordParams
johlju Aug 12, 2016
1a08f87
Changes for review number one
johlju Aug 12, 2016
4b6c96f
First test to use variables for mocking values
johlju Aug 12, 2016
f1d8202
Testing using variables in Mock
johlju Aug 13, 2016
4bc5f4f
Remove not needed property in mocks
johlju Aug 15, 2016
6d08569
Changes after review
johlju Aug 15, 2016
2e05d05
Resolved merge conflicts
johlju Aug 16, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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