Skip to content

Commit

Permalink
SqlScriptQuery: Increase speed of integration tests (dsccommunity#1128)
Browse files Browse the repository at this point in the history
- Changes to SqlScriptQuery
  - Make SqlScriptQuery integration tests dependent on SqlScript
    this is to shave of a few seconds on the integration tests.
  • Loading branch information
johlju authored May 15, 2018
1 parent 882a3a3 commit c214c96
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 89 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ A full list of changes in each version can be found in the [change log](CHANGELO
Services to use a database engine in another instance.
* [**SqlScript**](#sqlscript) resource to extend DSC Get/Set/Test
functionality to T-SQL.
* [**SqlScriptQuery**](#sqlscriptquery) resource to extend DSC Get/Set/Test
functionality to T-SQL.
* [**SqlServerConfiguration**](#sqlserverconfiguration) resource to manage
[SQL Server Configuration Options](https://msdn.microsoft.com/en-us/library/ms189631.aspx).
* [**SqlServerDatabaseMail**](#sqlserverdatabasemail) resource
Expand Down
36 changes: 1 addition & 35 deletions Tests/Integration/MSFT_SqlScriptQuery.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
and SqlServerRole, so any problems in those will be caught first, since
these integration tests are using those resources.
#>
[Microsoft.DscResourceKit.IntegrationTest(OrderNumber = 4)]
[Microsoft.DscResourceKit.IntegrationTest(OrderNumber = 5)]
param()

$script:DSCModuleName = 'SqlServerDsc'
Expand Down Expand Up @@ -57,40 +57,6 @@ try
$resourceId = "[$($script:DSCResourceFriendlyName)]Integration_Test"
}

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

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

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
<#
The Script resource generate _a lot_ of verbose output
which slows down the build worker. Verbose is turned
off for this particular test.
#>
Verbose = $false
Force = $true
ErrorAction = 'Stop'
}

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

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

Context ('When using configuration {0}' -f $configurationName) {
Expand Down
56 changes: 2 additions & 54 deletions Tests/Integration/MSFT_SqlScriptQuery.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ $ConfigurationData = @{
NodeName = 'localhost'
ServerName = $env:COMPUTERNAME
InstanceName = 'DSCSQL2016'
Database1Name = 'ScriptDatabase1'
Database2Name = 'ScriptDatabase2'
Database1Name = 'ScriptDatabase3'
Database2Name = 'ScriptDatabase4'

GetQuery = @'
SELECT Name FROM sys.databases WHERE Name = '$(DatabaseName)' FOR JSON AUTO
Expand All @@ -31,58 +31,6 @@ CREATE DATABASE [$(DatabaseName)]
)
}

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

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

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

node localhost
{
SqlServerLogin ('Create{0}' -f $UserCredential.UserName)
{
Ensure = 'Present'
Name = $UserCredential.UserName
LoginType = 'SqlLogin'
LoginCredential = $UserCredential
LoginMustChangePassword = $false
LoginPasswordExpirationEnabled = $true
LoginPasswordPolicyEnforced = $true
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName
PsDscRunAsCredential = $SqlAdministratorCredential
}

SqlServerRole ('Add{0}ToDbCreator' -f $UserCredential.UserName)
{
Ensure = 'Present'
ServerRoleName = 'dbcreator'
ServerName = $Node.ServerName
InstanceName = $Node.InstanceName
Members = @(
$UserCredential.UserName
)

PsDscRunAsCredential = $SqlAdministratorCredential
DependsOn = @(
('[SqlServerLogin]Create{0}' -f $UserCredential.UserName)
)
}
}
}

Configuration MSFT_SqlScriptQuery_RunSqlScriptQueryAsWindowsUser_Config
{
param
Expand Down
14 changes: 14 additions & 0 deletions Tests/Integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,17 @@ Database name | Owner
--- | ---
ScriptDatabase1 | $env:COMPUTERNAME\SqlAdmin
ScriptDatabase2 | DscAdmin1

## SqlScriptQuery

**Run order:** 5

**Depends on:** SqlScript

The integration test will leave the following databases on the SQL Server instance
**DSCSQL2016**.

Database name | Owner
--- | ---
ScriptDatabase3 | $env:COMPUTERNAME\SqlAdmin
ScriptDatabase4 | DscAdmin1

0 comments on commit c214c96

Please sign in to comment.