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.
Changes to xSQLServerAlwaysOnService
- Added integration test (issue dsccommunity#736).
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
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
94 changes: 94 additions & 0 deletions
94
Tests/Integration/MSFT_xSQLServerAlwaysOnService.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,94 @@ | ||
$script:DSCModuleName = 'xSQLServer' | ||
$script:DSCResourceFriendlyName = 'xSQLServerAlwaysOnService' | ||
$script:DSCResourceName = "MSFT_$($script:DSCResourceFriendlyName)" | ||
|
||
if (-not $env:APPVEYOR -eq $true) | ||
{ | ||
Write-Warning -Message ('Integration test for {0} will be skipped unless $env:APPVEYOR equals $true' -f $script:DSCResourceName) | ||
return | ||
} | ||
|
||
#region HEADER | ||
# Integration Test Template Version: 1.1.2 | ||
[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) | ||
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` | ||
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) | ||
{ | ||
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests')) | ||
} | ||
|
||
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force | ||
$TestEnvironment = Initialize-TestEnvironment ` | ||
-DSCModuleName $script:DSCModuleName ` | ||
-DSCResourceName $script:DSCResourceName ` | ||
-TestType Integration | ||
|
||
#endregion | ||
|
||
$mockComputerName = $env:COMPUTERNAME | ||
$mockInstanceName = 'DSCSQL2016' | ||
$mockRestartTimeout = 120 | ||
|
||
$mockSqlInstallAccountPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force | ||
$mockSqlInstallAccountUserName = "$env:COMPUTERNAME\SqlInstall" | ||
$mockSqlInstallCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlInstallAccountUserName, $mockSqlInstallAccountPassword | ||
|
||
try | ||
{ | ||
$ConfigurationData = @{ | ||
AllNodes = @( | ||
@{ | ||
NodeName = 'localhost' | ||
ComputerName = $mockComputerName | ||
InstanceName = $mockInstanceName | ||
RestartTimeout = $mockRestartTimeout | ||
|
||
PSDscAllowPlainTextPassword = $true | ||
} | ||
) | ||
} | ||
|
||
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" | ||
. $configFile | ||
|
||
$configurationName = "$($script:DSCResourceName)_EnableAlwaysOn_Config" | ||
$resourceId = "[$($script:DSCResourceFriendlyName)]Integration_Test" | ||
|
||
Describe "$($script:DSCResourceName)_Integration" { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
& $configurationName ` | ||
-SqlInstallCredential $mockSqlInstallCredential ` | ||
-OutputPath $TestDrive ` | ||
-ConfigurationData $ConfigurationData | ||
|
||
Start-DscConfiguration -Path $TestDrive ` | ||
-ComputerName localhost -Wait -Verbose -Force | ||
} | Should Not Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$currentConfiguration = Get-DscConfiguration | ||
|
||
$resourceCurrentState = $currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName | ||
} | Where-Object -FilterScript { | ||
$_.ResourceId -eq $resourceId | ||
} | ||
|
||
$resourceCurrentState.IsHadrEnabled | Should Be $true | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
#region FOOTER | ||
|
||
Restore-TestEnvironment -TestEnvironment $TestEnvironment | ||
|
||
#endregion | ||
} |
24 changes: 24 additions & 0 deletions
24
Tests/Integration/MSFT_xSQLServerAlwaysOnService.config.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,24 @@ | ||
configuration MSFT_xSQLServerAlwaysOnService_EnableAlwaysOn_Config | ||
{ | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.PSCredential] | ||
$SqlInstallCredential | ||
) | ||
|
||
Import-DscResource -ModuleName 'xSQLServer' | ||
|
||
node localhost { | ||
xSQLServerAlwaysOnService 'Integration_Test' | ||
{ | ||
Ensure = 'Present' | ||
SQLServer = $Node.ComputerName | ||
SQLInstanceName = $Node.InstanceName | ||
RestartTimeout = $Node.RestartTimeout | ||
|
||
PsDscRunAsCredential = $SqlInstallCredential | ||
} | ||
} | ||
} |