Skip to content

Commit

Permalink
Changes to SqlSetup
Browse files Browse the repository at this point in the history
- Refactor integration tests slightly to improve run time performance (issue dsccommunity#1001).
  • Loading branch information
johlju committed Jan 7, 2018
1 parent 60d19e6 commit 31ea433
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 82 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
and Tabular mode.
- Cleaned up integration tests.
- Added integration tests for installing a default instance of Database Engine.
- Refactor integration tests slightly to improve run time performance
([issue #1001](https://github.com/PowerShell/SqlServerDsc/issues/1001)).

## 10.0.0.0

Expand Down
163 changes: 83 additions & 80 deletions Tests/Integration/MSFT_SqlSetup.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,41 @@ $TestEnvironment = Initialize-TestEnvironment `

#endregion

<#
.SYNOPSIS
This function will output the Setup Bootstrap Summary.txt log file.
.DESCRIPTION
This function will output the Summary.txt log file, this is to be
able to debug any problems that potentially occurred during setup.
This will pick up the newest Summary.txt log file, so any
other log files will be ignored (AppVeyor build worker has
SQL Server instances installed by default).
This code is meant to work regardless what SQL Server
major version is used for the integration test.
#>
function Show-SqlBootstrapLog
{
[CmdletBinding()]
param
(
)

$summaryLogPath = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server\**\Setup Bootstrap\Log\Summary.txt' |
Sort-Object -Property LastWriteTime -Descending |
Select-Object -First 1

$summaryLog = Get-Content $summaryLogPath

Write-Verbose -Message $('-' * 80) -Verbose
Write-Verbose -Message 'Summary.txt' -Verbose
Write-Verbose -Message $('-' * 80) -Verbose
$summaryLog | ForEach-Object {
Write-Verbose $_ -Verbose
}
Write-Verbose -Message $('-' * 80) -Verbose
}


<#
Workaround for issue #774. In the appveyor.yml file the folder
Expand Down Expand Up @@ -113,12 +148,12 @@ try
$mockSqlAgentServiceSecondaryAccountUserName = "$env:COMPUTERNAME\svc-SqlAgentSec"
$mockSqlAgentServiceSecondaryCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlAgentServiceSecondaryAccountUserName, $mockSqlAgentServiceSecondaryAccountPassword

Describe "$($script:DSCResourceName)_InstallDatabaseEngineNamedInstanceAsSystem_Integration" {
Describe "$($script:DSCResourceName)_Integration" {
BeforeAll {
$resourceId = "[$($script:DSCResourceFriendlyName)]Integration_Test"
}

$configurationName = "$($script:DSCResourceName)_InstallDatabaseEngineNamedInstanceAsSystem_Config"
$configurationName = "$($script:DSCResourceName)_CreateDependencies_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
Expand Down Expand Up @@ -146,45 +181,55 @@ try
ErrorAction = 'Stop'
}

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

$configurationName = "$($script:DSCResourceName)_InstallDatabaseEngineNamedInstanceAsSystem_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
SqlInstallCredential = $mockSqlInstallCredential
SqlAdministratorCredential = $mockSqlAdminCredential
SqlServicePrimaryCredential = $mockSqlServicePrimaryCredential
SqlAgentServicePrimaryCredential = $mockSqlAgentServicePrimaryCredential
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
} -ErrorVariable itBlockError

# Check if previous It-block failed. If so output the SQL Server setup log file.
if ( $itBlockError.Count -ne 0 )
{
<#
Below code will output the Summary.txt log file, this is to be
able to debug any problems that potentially occurred during setup.
This will pick up the newest Summary.txt log file, so any
other log files will be ignored (AppVeyor build worker has
SQL Server instances installed by default).
This code is meant to work regardless what SQL Server
major version is used for the integration test.
#>
$summaryLogPath = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server\**\Setup Bootstrap\Log\Summary.txt' |
Sort-Object -Property LastWriteTime -Descending |
Select-Object -First 1

$summaryLog = Get-Content $summaryLogPath

Write-Verbose -Message $('-' * 80) -Verbose
Write-Verbose -Message 'Summary.txt' -Verbose
Write-Verbose -Message $('-' * 80) -Verbose
$summaryLog | ForEach-Object {
Write-Verbose $_ -Verbose
}
Write-Verbose -Message $('-' * 80) -Verbose
Show-SqlBootstrapLog
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
{
$script:currentConfiguration = 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 {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName
} | Where-Object -FilterScript {
$_.ResourceId -eq $resourceId
Expand Down Expand Up @@ -289,38 +334,17 @@ try
# Check if previous It-block failed. If so output the SQL Server setup log file.
if ( $itBlockError.Count -ne 0 )
{
<#
Below code will output the Summary.txt log file, this is to be
able to debug any problems that potentially occurred during setup.
This will pick up the newest Summary.txt log file, so any
other log files will be ignored (AppVeyor build worker has
SQL Server instances installed by default).
This code is meant to work regardless what SQL Server
major version is used for the integration test.
#>
$summaryLogPath = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server\**\Setup Bootstrap\Log\Summary.txt' |
Sort-Object -Property LastWriteTime -Descending |
Select-Object -First 1

$summaryLog = Get-Content $summaryLogPath

Write-Verbose -Message $('-' * 80) -Verbose
Write-Verbose -Message 'Summary.txt' -Verbose
Write-Verbose -Message $('-' * 80) -Verbose
$summaryLog | ForEach-Object {
Write-Verbose $_ -Verbose
}
Write-Verbose -Message $('-' * 80) -Verbose
Show-SqlBootstrapLog
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
{
$script:currentConfiguration = 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 {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName
} | Where-Object -FilterScript {
$_.ResourceId -eq $resourceId
Expand Down Expand Up @@ -421,38 +445,17 @@ try
# Check if previous It-block failed. If so output the SQL Server setup log file.
if ( $itBlockError.Count -ne 0 )
{
<#
Below code will output the Summary.txt log file, this is to be
able to debug any problems that potentially occurred during setup.
This will pick up the newest Summary.txt log file, so any
other log files will be ignored (AppVeyor build worker has
SQL Server instances installed by default).
This code is meant to work regardless what SQL Server
major version is used for the integration test.
#>
$summaryLogPath = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server\**\Setup Bootstrap\Log\Summary.txt' |
Sort-Object -Property LastWriteTime -Descending |
Select-Object -First 1

$summaryLog = Get-Content $summaryLogPath

Write-Verbose -Message $('-' * 80) -Verbose
Write-Verbose -Message 'Summary.txt' -Verbose
Write-Verbose -Message $('-' * 80) -Verbose
$summaryLog | ForEach-Object {
Write-Verbose $_ -Verbose
}
Write-Verbose -Message $('-' * 80) -Verbose
Show-SqlBootstrapLog
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
{
$script:currentConfiguration = 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 {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName
} | Where-Object -FilterScript {
$_.ResourceId -eq $resourceId
Expand Down
33 changes: 31 additions & 2 deletions Tests/Integration/MSFT_SqlSetup.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $ConfigurationData = @{
)
}

Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config
Configuration MSFT_SqlSetup_CreateDependencies_Config
{
param
(
Expand Down Expand Up @@ -96,7 +96,6 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config

Import-DscResource -ModuleName 'PSDscResources'
Import-DscResource -ModuleName 'xStorage'
Import-DscResource -ModuleName 'SqlServerDsc'

node localhost {
xMountImage 'MountIsoMedia'
Expand Down Expand Up @@ -167,7 +166,37 @@ Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
}
}

Configuration MSFT_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config
{
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$SqlInstallCredential,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$SqlServicePrimaryCredential,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$SqlAgentServicePrimaryCredential
)

Import-DscResource -ModuleName 'SqlServerDsc'

node localhost {
SqlSetup 'Integration_Test'
{
InstanceName = $Node.DatabaseEngineNamedInstanceName
Expand Down

0 comments on commit 31ea433

Please sign in to comment.