Skip to content

Commit 827cd5a

Browse files
committed
Add integration tests for Complete-SqlDscImage command
1 parent 3a97cb1 commit 827cd5a

File tree

5 files changed

+268
-0
lines changed

5 files changed

+268
-0
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
### Added
99

10+
- Added integration tests for `Complete-SqlDscImage` command to ensure command
11+
reliability in prepared image installation workflows. The test runs in a separate
12+
pipeline job `Integration_Test_Commands_SqlServer_PreparedImage` with its own CI
13+
worker, and verifies the completion of SQL Server instances prepared using
14+
`Install-SqlDscServer` with the `-PrepareImage` parameter. The test includes
15+
scenarios with minimal parameters and various service account/directory
16+
configurations [issue #2212](https://github.com/dsccommunity/SqlServerDsc/issues/2212).
17+
- Added integration test for `Install-SqlDscServer` with the `-PrepareImage`
18+
parameter set to support the prepared image installation workflow. This test
19+
(`Install-SqlDscServer.Integration.PrepareImage.Tests.ps1`) runs in the
20+
`Integration_Test_Commands_SqlServer_PreparedImage` pipeline job and prepares
21+
a DSCSQLTEST instance that is later completed by `Complete-SqlDscImage` tests
22+
[issue #2212](https://github.com/dsccommunity/SqlServerDsc/issues/2212).
1023
- Added integration tests for `Initialize-SqlDscRebuildDatabase` command to ensure
1124
command reliability. The test runs in group 8, alongside `Repair-SqlDscServer`,
1225
to verify the rebuild database functionality on the DSCSQLTEST instance

azure-pipelines.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,76 @@ stages:
381381
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
382382
testRunTitle: 'Integration Commands ($(TEST_CONFIGURATION) / $(JOB_VMIMAGE))'
383383

384+
- stage: Integration_Test_Commands_SqlServer_PreparedImage
385+
displayName: 'Integration Test Commands - SQL Server (Prepared Image)'
386+
dependsOn: Quality_Test_and_Unit_Test
387+
jobs:
388+
- job: Test_Integration_PreparedImage
389+
displayName: 'Commands - Prepared Image'
390+
strategy:
391+
matrix:
392+
SQL2017_WIN2022:
393+
JOB_VMIMAGE: 'windows-2022'
394+
TEST_CONFIGURATION: 'Integration_SQL2017'
395+
SQL2019_WIN2022:
396+
JOB_VMIMAGE: 'windows-2022'
397+
TEST_CONFIGURATION: 'Integration_SQL2019'
398+
SQL2019_WIN2025:
399+
JOB_VMIMAGE: 'windows-2025'
400+
TEST_CONFIGURATION: 'Integration_SQL2019'
401+
SQL2022_WIN2022:
402+
JOB_VMIMAGE: 'windows-2022'
403+
TEST_CONFIGURATION: 'Integration_SQL2022'
404+
SQL2022_WIN2025:
405+
JOB_VMIMAGE: 'windows-2025'
406+
TEST_CONFIGURATION: 'Integration_SQL2022'
407+
pool:
408+
vmImage: $(JOB_VMIMAGE)
409+
timeoutInMinutes: '0'
410+
steps:
411+
- task: DownloadPipelineArtifact@2
412+
displayName: 'Download Build Artifact'
413+
inputs:
414+
buildType: 'current'
415+
artifactName: $(buildArtifactName)
416+
targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)'
417+
- task: PowerShell@2
418+
name: configureWinRM
419+
displayName: 'Configure WinRM'
420+
inputs:
421+
targetType: 'inline'
422+
script: 'winrm quickconfig -quiet'
423+
pwsh: false
424+
- powershell: |
425+
Import-Module -Name ./tests/TestHelpers/CommonTestHelper.psm1
426+
Remove-PowerShellModuleFromCI -Name @('SqlServer', 'SQLPS')
427+
Remove-Module -Name CommonTestHelper
428+
name: cleanCIWorker
429+
displayName: 'Clean CI worker'
430+
- powershell: |
431+
./build.ps1 -Tasks test -CodeCoverageThreshold 0 -PesterTag $(TEST_CONFIGURATION) -PesterPath @(
432+
# Run the integration tests in a specific group order for prepared image workflow.
433+
# Group 0
434+
'tests/Integration/Commands/Prerequisites.Integration.Tests.ps1'
435+
'tests/Integration/Commands/Save-SqlDscSqlServerMediaFile.Integration.Tests.ps1'
436+
'tests/Integration/Commands/Import-SqlDscPreferredModule.Integration.Tests.ps1'
437+
# Group 1
438+
'tests/Integration/Commands/Install-SqlDscServer.Integration.PrepareImage.Tests.ps1'
439+
# Group 2
440+
'tests/Integration/Commands/Complete-SqlDscImage.Integration.Tests.ps1'
441+
# Group 9
442+
'tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1'
443+
)
444+
name: test
445+
displayName: 'Run Integration Test'
446+
- task: PublishTestResults@2
447+
displayName: 'Publish Test Results'
448+
condition: succeededOrFailed()
449+
inputs:
450+
testResultsFormat: 'NUnit'
451+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
452+
testRunTitle: 'Integration Commands - Prepared Image ($(TEST_CONFIGURATION) / $(JOB_VMIMAGE))'
453+
384454
- stage: Integration_Test_Commands_ReportingServices
385455
displayName: 'Integration Test Commands - Reporting Services'
386456
dependsOn: Integration_Test_Commands_SqlServer
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
2+
param ()
3+
4+
BeforeDiscovery {
5+
try
6+
{
7+
if (-not (Get-Module -Name 'DscResource.Test'))
8+
{
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
10+
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
11+
{
12+
# Redirect all streams to $null, except the error stream (stream 2)
13+
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
14+
}
15+
16+
# If the dependencies have not been resolved, this will throw an error.
17+
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
18+
}
19+
}
20+
catch [System.IO.FileNotFoundException]
21+
{
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
23+
}
24+
}
25+
26+
BeforeAll {
27+
$script:moduleName = 'SqlServerDsc'
28+
29+
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
30+
}
31+
32+
# cSpell: ignore DSCSQLTEST, PrepareImage, CompleteImage
33+
Describe 'Complete-SqlDscImage' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
34+
BeforeAll {
35+
Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose
36+
37+
$computerName = Get-ComputerName
38+
}
39+
40+
Context 'When completing a prepared SQL Server image' {
41+
It 'Should run the command without throwing' {
42+
# Set splatting parameters for Complete-SqlDscImage
43+
$completeSqlDscImageParameters = @{
44+
AcceptLicensingTerms = $true
45+
InstanceName = 'DSCSQLTEST'
46+
MediaPath = $env:IsoDrivePath
47+
Verbose = $true
48+
ErrorAction = 'Stop'
49+
Force = $true
50+
}
51+
52+
$null = Complete-SqlDscImage @completeSqlDscImageParameters
53+
}
54+
}
55+
56+
Context 'When completing a prepared image with service account parameters' {
57+
It 'Should run the command without throwing' {
58+
# Set splatting parameters for Complete-SqlDscImage with service account configuration
59+
$completeSqlDscImageParameters = @{
60+
AcceptLicensingTerms = $true
61+
InstanceName = 'DSCSQLTEST'
62+
SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName
63+
SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force
64+
SqlSvcStartupType = 'Automatic'
65+
AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $computerName
66+
AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force
67+
AgtSvcStartupType = 'Automatic'
68+
BrowserSvcStartupType = 'Automatic'
69+
SecurityMode = 'SQL'
70+
SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
71+
SqlSysAdminAccounts = @(
72+
('{0}\SqlAdmin' -f $computerName)
73+
)
74+
MediaPath = $env:IsoDrivePath
75+
Verbose = $true
76+
ErrorAction = 'Stop'
77+
Force = $true
78+
}
79+
80+
$null = Complete-SqlDscImage @completeSqlDscImageParameters
81+
}
82+
}
83+
84+
Context 'When completing a prepared image with SQL Server directory parameters' {
85+
It 'Should run the command without throwing' {
86+
# Set splatting parameters for Complete-SqlDscImage with directory configuration
87+
$completeSqlDscImageParameters = @{
88+
AcceptLicensingTerms = $true
89+
InstanceName = 'DSCSQLTEST'
90+
InstallSqlDataDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data'
91+
SqlBackupDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Backup'
92+
SqlTempDbDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data'
93+
SqlTempDbLogDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data'
94+
SqlUserDbDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data'
95+
SqlUserDbLogDir = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data'
96+
TcpEnabled = $true
97+
NpEnabled = $false
98+
MediaPath = $env:IsoDrivePath
99+
Verbose = $true
100+
ErrorAction = 'Stop'
101+
Force = $true
102+
}
103+
104+
$null = Complete-SqlDscImage @completeSqlDscImageParameters
105+
}
106+
}
107+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
2+
param ()
3+
4+
BeforeDiscovery {
5+
try
6+
{
7+
if (-not (Get-Module -Name 'DscResource.Test'))
8+
{
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
10+
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
11+
{
12+
# Redirect all streams to $null, except the error stream (stream 2)
13+
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
14+
}
15+
16+
# If the dependencies have not been resolved, this will throw an error.
17+
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
18+
}
19+
}
20+
catch [System.IO.FileNotFoundException]
21+
{
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
23+
}
24+
}
25+
26+
BeforeAll {
27+
$script:moduleName = 'SqlServerDsc'
28+
29+
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
30+
}
31+
32+
# cSpell: ignore SQLSERVERAGENT, DSCSQLTEST, PrepareImage
33+
Describe 'Install-SqlDscServer - PrepareImage' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
34+
BeforeAll {
35+
Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose
36+
37+
$computerName = Get-ComputerName
38+
}
39+
40+
Context 'When using PrepareImage parameter set' {
41+
Context 'When preparing database engine instance for image' {
42+
It 'Should run the command without throwing' {
43+
# Set splatting parameters for Install-SqlDscServer with PrepareImage
44+
$installSqlDscServerParameters = @{
45+
PrepareImage = $true
46+
AcceptLicensingTerms = $true
47+
InstanceName = 'DSCSQLTEST'
48+
Features = 'SQLENGINE'
49+
InstallSharedDir = 'C:\Program Files\Microsoft SQL Server'
50+
InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server'
51+
MediaPath = $env:IsoDrivePath
52+
Verbose = $true
53+
ErrorAction = 'Stop'
54+
Force = $true
55+
}
56+
57+
$null = Install-SqlDscServer @installSqlDscServerParameters
58+
}
59+
}
60+
}
61+
}

tests/Integration/Commands/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ Initialize-SqlDscRebuildDatabase | 8 | 1 (Install-SqlDscServer) | DSCSQLTEST | -
125125
Uninstall-SqlDscServer | 9 | 8 (Repair-SqlDscServer), 8 (Initialize-SqlDscRebuildDatabase) | - | -
126126
<!-- markdownlint-enable MD013 -->
127127

128+
### Integration_Test_Commands_SqlServer_PreparedImage
129+
130+
Tests for SQL Server Database Engine commands using the prepared image installation
131+
workflow. This test suite runs in a separate job with its own CI worker, testing
132+
`Install-SqlDscServer` with `-PrepareImage` followed by `Complete-SqlDscImage`.
133+
134+
<!-- markdownlint-disable MD013 -->
135+
Command | Run order # | Depends on # | Use instance | Creates persistent objects
136+
--- | --- | --- | --- | ---
137+
Prerequisites | 0 | - | - | Sets up dependencies
138+
Save-SqlDscSqlServerMediaFile | 0 | - | - | Downloads SQL Server media files
139+
Import-SqlDscPreferredModule | 0 | - | - | -
140+
Install-SqlDscServer (PrepareImage) | 1 | 0 (Prerequisites) | - | DSCSQLTEST instance prepared
141+
Complete-SqlDscImage | 2 | 1 (Install-SqlDscServer) | DSCSQLTEST | Completes prepared image installation
142+
Uninstall-SqlDscServer | 9 | 2 (Complete-SqlDscImage) | - | -
143+
<!-- markdownlint-enable MD013 -->
144+
128145
### Integration_Test_Commands_ReportingServices
129146

130147
Tests for SQL Server Reporting Services commands.

0 commit comments

Comments
 (0)