Skip to content

Commit

Permalink
Changes to xSQLServerAlwaysOnService
Browse files Browse the repository at this point in the history
- Added integration test (issue dsccommunity#736).
  • Loading branch information
johlju committed Sep 14, 2017
1 parent 97af610 commit 3509827
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
- Fixed PS Script Analyzer errors ([issue #724](https://github.com/PowerShell/xSQLServer/issues/724))
- Casting the result of the property IsHadrEnabled to [System.Boolean] so that
$null is never returned, which resulted in an exception ([issue #763](https://github.com/PowerShell/xFailOverCluster/issues/763)).
- Added integration test ([issue #736](https://github.com/PowerShell/xSQLServer/issues/736)).
- Changes to xSQLServerDatabasePermission
- Fixed PS Script Analyzer errors ([issue #725](https://github.com/PowerShell/xSQLServer/issues/725))
- Changes to xSQLServerScript
Expand Down
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 Tests/Integration/MSFT_xSQLServerAlwaysOnService.config.ps1
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
}
}
}

0 comments on commit 3509827

Please sign in to comment.