Skip to content

Commit

Permalink
SqlServerDsc: style cleanup in tests (dsccommunity#1020)
Browse files Browse the repository at this point in the history
- Changes to SqlServerDsc
  - Style cleanup in helper function tests.
- Changes to SqlAG
  - Fixed typos in tests.
  - Style cleanup in tests.
- Changes to SqlAGDatabase
  - Style cleanup in tests.
- Changes to SqlAGListener
  - Style cleanup in tests.
- Changes to SqlAGReplica
  - Style cleanup in tests.
- Changes to SqlAlias
  - Style cleanup in tests
- Changes to SqlAlwaysOnService
  - Style cleanup in tests
- Changes to SqlScript
  - Style cleanup in tests
- Changes to SqlServerConfiguration
  - Style cleanup in tests
- Changes to SqlServerEndpoint
  - Style cleanup in tests
- Changes to SqlServerLogin
  - Style cleanup in tests
- Changes to SqlSetup
  - Style cleanup in tests
  • Loading branch information
johlju authored Jan 15, 2018
1 parent 4f09846 commit 4678b02
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 115 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,29 @@
renamed the repository the security token was changed
([issue #1012](https://github.com/PowerShell/SqlServerDsc/issues/1012)).
- Fixed typo in comment-base help for helper function Test-AvailabilityReplicaSeedingModeAutomatic.
- Style cleanup in helper function tests.
- Changes to SqlAG
- Fixed typos in tests.
- Style cleanup in tests.
- Changes to SqlAGDatabase
- Style cleanup in tests.
- Changes to SqlAGListener
- Fixed typo in comment-based help.
- Style cleanup in tests.
- Changes to SqlAGReplica
- Minor code style cleanup. Removed unused variable and instead piped the cmdlet
Join-SqlAvailabilityGroup to Out-Null.
- Fixed minor typos in comment-based help.
- Fixed minor typos in comment.
- Style cleanup in tests.
- Changes to SqlAlias
- Fixed issue where exception was thrown if reg keys did not exist
([issue #949](https://github.com/PowerShell/SqlServerDsc/issues/949)).
- Style cleanup in tests.
- Changes to SqlAlwaysOnService
- Refactor integration tests slightly to improve run time performance
([issue #1001](https://github.com/PowerShell/SqlServerDsc/issues/1001)).
- Style cleanup in tests.
- Changes to SqlDatabase
- Fix minor Script Analyzer warning.
- Changes to SqlDatabaseDefaultLocation
Expand All @@ -71,16 +81,21 @@
([issue #634](https://github.com/PowerShell/SqlServerDsc/issues/634)).
- Refactor integration tests slightly to improve run time performance
([issue #1001](https://github.com/PowerShell/SqlServerDsc/issues/1001)).
- Changes to SqlScript
- Style cleanup in tests.
- Changes to SqlServerConfiguration
- Fixed minor typos in comment-based help.
- Style cleanup in tests.
- Changes to SqlServerEndpoint
- Updated README.md with links to the examples
([issue #504](https://github.com/PowerShell/SqlServerDsc/issues/504)).
- Style cleanup in tests.
- Changes to SqlServerLogin
- Added integration tests ([issue #748](https://github.com/PowerShell/SqlServerDsc/issues/748)).
- Minor code style cleanup.
- Removed unused variable and instead piped the helper function Connect-SQL to
Out-Null.
- Style cleanup in tests.
- Changes to SqlServerMaxDop
- Minor style changes in the helper function Get-SqlDscDynamicMaxDop.
- Changes to SqlServerMemory
Expand Down Expand Up @@ -121,6 +136,7 @@
- Added PSSA rule 'PSUseDeclaredVarsMoreThanAssignments' override in the
function Set-TargetResource for the variable $global:DSCMachineStatus.
- Style cleanup in helper function ConvertTo-Decimal.
- Style cleanup in tests.
- Changes to SqlWindowsFirewall
- Fixed minor typos in comment-based help.
- Minor code style cleanup.
Expand Down
44 changes: 22 additions & 22 deletions Tests/Unit/MSFT_SqlAG.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ try
$mockIsHadrEnabled = $true
$mockIsDatabaseMirroringEndpointPresent = $true

$mockServerObjectProperies = @{
$mockServerObjectProperties = @{
Server1 = @{
NetName = 'Server1'
}
Expand All @@ -96,7 +96,7 @@ try
FailureConditionLevel = 'OnCriticalServerErrors' # Not the default parameter value
HealthCheckTimeout = 20000
Name = $mockNameParameters.PresentAvailabilityGroup
PrimaryReplicaServerName = $mockServerObjectProperies.Server1.NetName
PrimaryReplicaServerName = $mockServerObjectProperties.Server1.NetName
}

$mockAvailabilityGroupReplicaProperties = @{
Expand All @@ -105,11 +105,11 @@ try
BackupPriority = 49 # Not the default parameter value
ConnectionModeInPrimaryRole = 'AllowAllConnections' # Not the default parameter value
ConnectionModeInSecondaryRole = 'AllowNoConnections' # Not the default parameter value
EndpointHostName = $mockServerObjectProperies.Server1.NetName
EndpointHostName = $mockServerObjectProperties.Server1.NetName
EndpointProtocol = 'TCP'
EndpointPort = 5022
FailoverMode = 'Automatic' # Not the default parameter value
Name = $mockServerObjectProperies.Server1.NetName
Name = $mockServerObjectProperties.Server1.NetName
Role = 'Primary'
}

Expand All @@ -118,11 +118,11 @@ try
BackupPriority = 49 # Not the default parameter value
ConnectionModeInPrimaryRole = 'AllowAllConnections' # Not the default parameter value
ConnectionModeInSecondaryRole = 'AllowNoConnections' # Not the default parameter value
EndpointHostName = $mockServerObjectProperies.Server2.NetName
EndpointHostName = $mockServerObjectProperties.Server2.NetName
EndpointProtocol = 'TCP'
EndpointPort = 5022
FailoverMode = 'Automatic' # Not the default parameter value
Name = $mockServerObjectProperies.Server2.NetName
Name = $mockServerObjectProperties.Server2.NetName
Role = 'Primary'
}
}
Expand Down Expand Up @@ -488,7 +488,7 @@ try
{
$mockSqlServer = $SQLServer
}
$mockCurrentServerObjectProperties = $mockServerObjectProperies.$mockSqlServer
$mockCurrentServerObjectProperties = $mockServerObjectProperties.$mockSqlServer

# Build the domain instance name
if ( ( $SQLInstanceName -eq 'MSSQLSERVER' ) -or [string]::IsNullOrEmpty($SQLInstanceName) )
Expand Down Expand Up @@ -597,7 +597,7 @@ try
}

# Mock the Update-AvailabilityGroup function to ensure the specified property was set correctly
$mockUpdateAvailabiltyGroup = {
$mockUpdateAvailabilityGroup = {
param
(
[Parameter()]
Expand All @@ -623,7 +623,7 @@ try
}

# Mock the Update-AvailabilityGroupReplica function to ensure the specified property was set correctly
$mockUpdateAvailabiltyGroupReplica = {
$mockUpdateAvailabilityGroupReplica = {
param
(
[Parameter()]
Expand Down Expand Up @@ -774,23 +774,23 @@ try
BeforeAll {
Mock -CommandName Connect-SQL -MockWith $mockConnectSql -Verifiable
Mock -CommandName Get-PrimaryReplicaServerObject -MockWith $mockConnectSql -Verifiable
Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable
Mock -CommandName Import-SQLPSModule -Verifiable
Mock -CommandName New-SqlAvailabilityGroup $mockNewSqlAvailabilityGroup -Verifiable
Mock -CommandName New-SqlAvailabilityReplica -MockWith $mockNewSqlAvailabilityGroupReplica -Verifiable
Mock -CommandName New-TerminatingError -MockWith {
$ErrorType
} -Verifiable
Mock -CommandName Remove-SqlAvailabilityGroup -MockWith {} -Verifiable -ParameterFilter {
Mock -CommandName Remove-SqlAvailabilityGroup -Verifiable -ParameterFilter {
$InputObject.Name -eq $mockNameParameters.PresentAvailabilityGroup
}
Mock -CommandName Remove-SqlAvailabilityGroup -MockWith {
throw 'RemoveAvailabilityGroupFailed'
} -Verifiable -ParameterFilter {
$InputObject.Name -eq $mockNameParameters.RemoveAvailabilityGroupFailed
}
Mock -CommandName Test-ClusterPermissions -MockWith {} -Verifiable
Mock -CommandName Update-AvailabilityGroup -MockWith $mockUpdateAvailabiltyGroup -Verifiable
Mock -CommandName Update-AvailabilityGroupReplica -MockWith $mockUpdateAvailabiltyGroupReplica -Verifiable
Mock -CommandName Test-ClusterPermissions -Verifiable
Mock -CommandName Update-AvailabilityGroup -MockWith $mockUpdateAvailabilityGroup -Verifiable
Mock -CommandName Update-AvailabilityGroupReplica -MockWith $mockUpdateAvailabilityGroupReplica -Verifiable
}

Context 'When the Availability Group is Absent and the desired state is Present and a parameter is supplied' {
Expand Down Expand Up @@ -920,13 +920,13 @@ try

if ( $mockAvailabilityGroupProperties.Keys -contains $ParameterName )
{
$assertUpdateAvailbilityGroupMockCalled = 1
$assertUpdateAvailbilityGroupReplicaMockCalled = 0
$assertUpdateAvailabilityGroupMockCalled = 1
$assertUpdateAvailabilityGroupReplicaMockCalled = 0
}
elseif ( $mockAvailabilityGroupReplicaProperties.Server1.Keys -contains $ParameterName )
{
$assertUpdateAvailbilityGroupMockCalled = 0
$assertUpdateAvailbilityGroupReplicaMockCalled = 1
$assertUpdateAvailabilityGroupMockCalled = 0
$assertUpdateAvailabilityGroupReplicaMockCalled = 1
}

Set-TargetResource @setTargetResourceParameters
Expand All @@ -945,8 +945,8 @@ try
$InputObject.Name -eq $mockNameParameters.RemoveAvailabilityGroupFailed
}
Assert-MockCalled -CommandName Test-ClusterPermissions -Scope It -Times 1 -Exactly
Assert-MockCalled -CommandName Update-AvailabilityGroup -Scope It -Times $assertUpdateAvailbilityGroupMockCalled -Exactly
Assert-MockCalled -CommandName Update-AvailabilityGroupReplica -Scope It -Times $assertUpdateAvailbilityGroupReplicaMockCalled -Exactly
Assert-MockCalled -CommandName Update-AvailabilityGroup -Scope It -Times $assertUpdateAvailabilityGroupMockCalled -Exactly
Assert-MockCalled -CommandName Update-AvailabilityGroupReplica -Scope It -Times $assertUpdateAvailabilityGroupReplicaMockCalled -Exactly
}
}

Expand Down Expand Up @@ -1303,7 +1303,7 @@ try
}
}

Context 'When the Availability Group is Present an Enpoint property is incorrect' {
Context 'When the Availability Group is Present an Endpoint property is incorrect' {
AfterEach {
# Restore up the original endpoint url settings
$mockAvailabilityGroupReplicaProperties.Server1 = $mockAvailabilityGroupReplicaPropertiesServer1Original.Clone()
Expand Down Expand Up @@ -1406,7 +1406,7 @@ try
Assert-MockCalled -CommandName New-TerminatingError -Scope It -Times 0 -Exactly
}

It 'Should throw the correct error, AlterAvailabilityGroupFailed, when altering the Availaiblity Group fails' {
It 'Should throw the correct error, AlterAvailabilityGroupFailed, when altering the Availability Group fails' {

$mockAvailabilityGroup.Name = 'AlterFailed'

Expand Down
26 changes: 13 additions & 13 deletions Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ WITH NORECOVERY'
Describe 'SqlAGDatabase\Get-TargetResource' {
BeforeAll {
Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable
Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable
Mock -CommandName Import-SQLPSModule -Verifiable
}

BeforeEach {
Expand Down Expand Up @@ -426,14 +426,14 @@ WITH NORECOVERY'
BeforeAll {
Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' }
Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServer2Object } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' }
Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable
Mock -CommandName Invoke-Query -MockWith {} -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabase
Mock -CommandName Invoke-Query -MockWith {} -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabaseWithExecuteAs
Mock -CommandName Import-SQLPSModule -Verifiable
Mock -CommandName Invoke-Query -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabase
Mock -CommandName Invoke-Query -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabaseWithExecuteAs
Mock -CommandName Join-Path -MockWith { [IO.Path]::Combine($databaseMembershipClass.BackupPath,"$($database.Name)_Full_$(Get-Date -Format 'yyyyMMddhhmmss').bak") } -Verifiable -ParameterFilter { $ChildPath -like '*_Full_*.bak' }
Mock -CommandName Join-Path -MockWith { [IO.Path]::Combine($databaseMembershipClass.BackupPath,"$($database.Name)_Log_$(Get-Date -Format 'yyyyMMddhhmmss').trn") } -Verifiable -ParameterFilter { $ChildPath -like '*_Log_*.trn' }
Mock -CommandName New-TerminatingError { $ErrorType } -Verifiable
Mock -CommandName Remove-Item -MockWith {} -Verifiable
Mock -CommandName Restore-SqlDatabase -MockWith {} -Verifiable
Mock -CommandName Remove-Item -Verifiable
Mock -CommandName Restore-SqlDatabase -Verifiable
}

BeforeEach {
Expand All @@ -448,17 +448,17 @@ WITH NORECOVERY'
MatchDatabaseOwner = $true
}

Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' }
Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' }
Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Primary' }
Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Secondary' }
Mock -CommandName Backup-SqlDatabase -MockWith {} -Verifiable -ParameterFilter { $BackupAction -eq 'Database' }
Mock -CommandName Backup-SqlDatabase -MockWith {} -Verifiable -ParameterFilter { $BackupAction -eq 'Log'}
Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' }
Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' }
Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Primary' }
Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Secondary' }
Mock -CommandName Backup-SqlDatabase -Verifiable -ParameterFilter { $BackupAction -eq 'Database' }
Mock -CommandName Backup-SqlDatabase -Verifiable -ParameterFilter { $BackupAction -eq 'Log'}
Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $SqlServer -eq 'Server1' -and $SQLInstanceName -eq 'MSSQLSERVER' }
Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $SqlServer -eq 'Server1' }
Mock -CommandName Connect-SQL -MockWith { return $mockServer2Object } -Verifiable -ParameterFilter { $SqlServer -eq 'Server2' }
Mock -CommandName Invoke-Query -MockWith $mockResultInvokeQueryFileExist -Verifiable -ParameterFilter { $Query -like 'EXEC master.dbo.xp_fileexist *' }
Mock -CommandName Remove-SqlAvailabilityDatabase -MockWith {} -Verifiable
Mock -CommandName Remove-SqlAvailabilityDatabase -Verifiable
Mock -CommandName Test-ImpersonatePermissions -MockWith { $true } -Verifiable
}

Expand Down
12 changes: 6 additions & 6 deletions Tests/Unit/MSFT_SqlAGListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ try

Context 'When the system is not in the desired state' {

Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -Verifiable
Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Verifiable

It 'Should return the desired state as absent' {
$result = Get-TargetResource @testParameters
Expand Down Expand Up @@ -238,7 +238,7 @@ try
$testParameters['Port'] = 5030
$testParameters['DHCP'] = $false

Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -Verifiable
Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Verifiable

$result = Test-TargetResource @testParameters
$result | Should -Be $false
Expand Down Expand Up @@ -404,7 +404,7 @@ try
$testParameters['Port'] = 5030
$testParameters['DHCP'] = $false

Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -Verifiable
Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Verifiable

$result = Test-TargetResource @testParameters
$result | Should -Be $true
Expand Down Expand Up @@ -516,9 +516,9 @@ try
$testParameters = $defaultParameters.Clone()

Mock -CommandName Connect-SQL -MockWith $mockConnectSql -Verifiable
Mock -CommandName New-SqlAvailabilityGroupListener -MockWith {} -Verifiable
Mock -CommandName Set-SqlAvailabilityGroupListener -MockWith {} -Verifiable
Mock -CommandName Add-SqlAvailabilityGroupListenerStaticIp -MockWith {} -Verifiable
Mock -CommandName New-SqlAvailabilityGroupListener -Verifiable
Mock -CommandName Set-SqlAvailabilityGroupListener -Verifiable
Mock -CommandName Add-SqlAvailabilityGroupListenerStaticIp -Verifiable
}

Context 'When the system is not in the desired state' {
Expand Down
Loading

0 comments on commit 4678b02

Please sign in to comment.