forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add integration tests (issue dsccommunity#755)
- Loading branch information
Showing
5 changed files
with
395 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
245 changes: 245 additions & 0 deletions
245
tests/Integration/DSC_SqlServerReplication.Integration.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.