Skip to content

Commit

Permalink
Changes to SqlServerReplication
Browse files Browse the repository at this point in the history
- Add integration tests (issue dsccommunity#755)
  • Loading branch information
johlju committed May 5, 2020
1 parent 7a22e7e commit 08e7d07
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
- SqlSetup
- A read only property `IsClustered` was added that can be used to determine
if the instance is clustered.
- SqlServerReplication
- Add integration tests ([issue #755](https://github.com/dsccommunity/SqlServerDsc/issues/755)
- SqlServerDsc.Common
- The helper function `Restart-SqlService` was improved to handle Failover
Clusters better. Now the SQL Server service will only be taken offline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Configuration Example
InstanceName = 'MSSQLSERVER'
AdminLinkCredentials = $SqlAdministratorCredential
DistributorMode = 'Local'
DistributionDBName = 'Database1'
WorkingDirectory = 'C:\Temp'

PsDscRunAsCredential = $SqlAdministratorCredential
Expand Down
245 changes: 245 additions & 0 deletions tests/Integration/DSC_SqlServerReplication.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')

if (-not (Test-BuildCategory -Type 'Integration' -Category @('Integration_SQL2016','Integration_SQL2017')))
{
return
}

$script:dscModuleName = 'SqlServerDsc'
$script:dscResourceFriendlyName = 'SqlServerProtocolTcpIp'
$script:dscResourceName = "DSC_$($script:dscResourceFriendlyName)"

try
{
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
}
catch [System.IO.FileNotFoundException]
{
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
}

$script:testEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-ResourceType 'Mof' `
-TestType 'Integration'

try
{
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $configFile

Describe "$($script:dscResourceName)_Integration" {
BeforeAll {
$resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test"
}

$configurationName = "$($script:dscResourceName)_AddDistributor_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Verbose = $true
Force = $true
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop
} | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.Ensure | Should -Be 'Present'
$resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName
$resourceCurrentState.DistributorMode | Should -Be 'Local'
$resourceCurrentState.DistributionDBName | Should -Be 'Database1'
$resourceCurrentState.RemoteDistributor | Should -BeNullOrEmpty
$resourceCurrentState.WorkingDirectory | Should -Be 'C:\Temp'
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}

$configurationName = "$($script:dscResourceName)_RemoveDistributor_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Verbose = $true
Force = $true
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop
} | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.Ensure | Should -Be 'Present'
$resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName
$resourceCurrentState.DistributorMode | Should -Be 'Local'
$resourceCurrentState.DistributionDBName | Should -BeNullOrEmpty
$resourceCurrentState.RemoteDistributor | Should -BeNullOrEmpty
$resourceCurrentState.WorkingDirectory | Should -BeNullOrEmpty
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}

$configurationName = "$($script:dscResourceName)_AddPublisher_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Verbose = $true
Force = $true
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop
} | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.Ensure | Should -Be 'Present'
$resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName
$resourceCurrentState.DistributorMode | Should -Be 'Remote'
$resourceCurrentState.DistributionDBName | Should -BeNullOrEmpty
$resourceCurrentState.RemoteDistributor | Should -Be 'distsqlsrv.company.local'
$resourceCurrentState.WorkingDirectory | Should -Be 'C:\Temp'
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}

$configurationName = "$($script:dscResourceName)_RemovePublisher_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Verbose = $true
Force = $true
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop
} | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.Ensure | Should -Be 'Present'
$resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName
$resourceCurrentState.DistributorMode | Should -Be 'Remote'
$resourceCurrentState.DistributionDBName | Should -BeNullOrEmpty
$resourceCurrentState.RemoteDistributor | Should -BeNullOrEmpty
$resourceCurrentState.WorkingDirectory | Should -BeNullOrEmpty
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}
}
}
finally
{
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}
Loading

0 comments on commit 08e7d07

Please sign in to comment.