Skip to content

Commit 542be63

Browse files
committed
Add integration tests for Repair-SqlDscServer command
1 parent c52ea50 commit 542be63

File tree

4 files changed

+134
-11
lines changed

4 files changed

+134
-11
lines changed

CHANGELOG.md

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

88
### Added
99

10+
- Added integration tests for `Repair-SqlDscServer` command to ensure command
11+
reliability. The test runs in group 8, before `Uninstall-SqlDscServer` in
12+
group 9, to verify the repair functionality on the DSCSQLTEST instance
13+
[issue #2238](https://github.com/dsccommunity/SqlServerDsc/issues/2238).
1014
- Added integration tests for `ConvertTo-SqlDscServerPermission` command to ensure
1115
command reliability [issue #2207](https://github.com/dsccommunity/SqlServerDsc/issues/2207).
1216
- Added post-installation configuration integration test to configure SSL certificate

azure-pipelines.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ stages:
354354
'tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1'
355355
'tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1'
356356
'tests/Integration/Commands/Add-SqlDscTraceFlag.Integration.Tests.ps1'
357-
# Group 8
357+
# Group 7
358358
'tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1'
359359
'tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1'
360360
'tests/Integration/Commands/Enable-SqlDscAudit.Integration.Tests.ps1'
@@ -365,6 +365,8 @@ stages:
365365
'tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1'
366366
'tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1'
367367
'tests/Integration/Commands/Remove-SqlDscTraceFlag.Integration.Tests.ps1'
368+
# Group 8
369+
'tests/Integration/Commands/Repair-SqlDscServer.Integration.Tests.ps1'
368370
# Group 9
369371
'tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1'
370372
)

tests/Integration/Commands/README.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ a higher run order number than the highest run order of the dependent
3535
integration tests.
3636

3737
**Below are the integration tests listed in the run order, and with the dependency
38-
to each other. Dependencies are made to speed up the testing.**
38+
to each other. Dependencies are made to speed up the testing. The tests are
39+
organized by Azure Pipeline job.**
40+
41+
### Integration_Test_Commands_SqlServer
42+
43+
Tests for SQL Server Database Engine commands.
3944

4045
<!-- markdownlint-disable MD013 -->
4146
Command | Run order # | Depends on # | Use instance | Creates persistent objects
@@ -107,22 +112,50 @@ Disable-SqlDscAgentOperator | 4 | 1 (Install-SqlDscServer), 0 (Prerequisites) |
107112
Get-SqlDscAudit | 4 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
108113
Disable-SqlDscAudit | 4 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
109114
Add-SqlDscTraceFlag | 4 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | -
110-
Remove-SqlDscAgentAlert | 8 | 4 (New-SqlDscAgentAlert) | DSCSQLTEST | -
111-
Remove-SqlDscAgentOperator | 8 | 4 (New-SqlDscAgentOperator) | DSCSQLTEST | -
112-
Remove-SqlDscAudit | 8 | - | DSCSQLTEST | -
113-
Set-SqlDscAudit | 8 | - | DSCSQLTEST | -
114-
Remove-SqlDscDatabase | 8 | 4 (New-SqlDscDatabase) | DSCSQLTEST | -
115-
Remove-SqlDscRole | 8 | 4 (New-SqlDscRole) | DSCSQLTEST | -
116-
Remove-SqlDscLogin | 8 | 4 (New-SqlDscLogin) | DSCSQLTEST | -
117-
Remove-SqlDscTraceFlag | 8 | 1 (Install-SqlDscServer) | DSCSQLTEST | -
118-
Uninstall-SqlDscServer | 9 | 8 (Remove commands) | - | -
115+
Remove-SqlDscAgentAlert | 7 | 4 (New-SqlDscAgentAlert) | DSCSQLTEST | -
116+
Remove-SqlDscAgentOperator | 7 | 4 (New-SqlDscAgentOperator) | DSCSQLTEST | -
117+
Remove-SqlDscAudit | 7 | - | DSCSQLTEST | -
118+
Set-SqlDscAudit | 7 | - | DSCSQLTEST | -
119+
Remove-SqlDscDatabase | 7 | 4 (New-SqlDscDatabase) | DSCSQLTEST | -
120+
Remove-SqlDscRole | 7 | 4 (New-SqlDscRole) | DSCSQLTEST | -
121+
Remove-SqlDscLogin | 7 | 4 (New-SqlDscLogin) | DSCSQLTEST | -
122+
Remove-SqlDscTraceFlag | 7 | 1 (Install-SqlDscServer) | DSCSQLTEST | -
123+
Repair-SqlDscServer | 8 | 1 (Install-SqlDscServer) | DSCSQLTEST | -
124+
Uninstall-SqlDscServer | 9 | 8 (Repair-SqlDscServer) | - | -
125+
<!-- markdownlint-enable MD013 -->
126+
127+
### Integration_Test_Commands_ReportingServices
128+
129+
Tests for SQL Server Reporting Services commands.
130+
131+
<!-- markdownlint-disable MD013 -->
132+
Command | Run order # | Depends on # | Use instance | Creates persistent objects
133+
--- | --- | --- | --- | ---
134+
Prerequisites | 0 | - | - | Sets up dependencies
135+
Save-SqlDscSqlServerMediaFile | 0 | - | - | Downloads SQL Server media files
136+
Import-SqlDscPreferredModule | 0 | - | - | -
119137
Install-SqlDscReportingService | 1 | 0 (Prerequisites) | - | SSRS instance
120138
Get-SqlDscInstalledInstance | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
121139
Get-SqlDscRSSetupConfiguration | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
122140
Test-SqlDscRSInstalled | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
123141
Repair-SqlDscReportingService | 8 | 1 (Install-SqlDscReportingService) | SSRS | -
124142
Uninstall-SqlDscReportingService | 9 | 8 (Repair-SqlDscReportingService) | - | -
143+
<!-- markdownlint-enable MD013 -->
144+
145+
### Integration_Test_Commands_BIReportServer
146+
147+
Tests for Power BI Report Server commands.
148+
149+
<!-- markdownlint-disable MD013 -->
150+
Command | Run order # | Depends on # | Use instance | Creates persistent objects
151+
--- | --- | --- | --- | ---
152+
Prerequisites | 0 | - | - | Sets up dependencies
153+
Save-SqlDscSqlServerMediaFile | 0 | - | - | Downloads SQL Server media files
154+
Import-SqlDscPreferredModule | 0 | - | - | -
125155
Install-SqlDscBIReportServer | 1 | 0 (Prerequisites) | - | PBIRS instance
156+
Get-SqlDscInstalledInstance | 2 | 1 (Install-SqlDscBIReportServer), 0 (Prerequisites) | PBIRS | -
157+
Get-SqlDscRSSetupConfiguration | 2 | 1 (Install-SqlDscBIReportServer), 0 (Prerequisites) | PBIRS | -
158+
Test-SqlDscRSInstalled | 2 | 1 (Install-SqlDscBIReportServer), 0 (Prerequisites) | PBIRS | -
126159
Repair-SqlDscBIReportServer | 8 | 1 (Install-SqlDscBIReportServer) | PBIRS | -
127160
Uninstall-SqlDscBIReportServer | 9 | 8 (Repair-SqlDscBIReportServer) | - | -
128161
<!-- markdownlint-enable MD013 -->
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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
33+
Describe 'Repair-SqlDscServer' -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+
38+
It 'Should have the named instance SQL Server service running' {
39+
$getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop'
40+
41+
$getServiceResult.Status | Should -Be 'Running'
42+
}
43+
44+
Context 'When repairing a named instance' {
45+
It 'Should run the repair command without throwing' {
46+
# Set splatting parameters for Repair-SqlDscServer
47+
$repairSqlDscServerParameters = @{
48+
InstanceName = 'DSCSQLTEST'
49+
Features = 'SQLENGINE'
50+
MediaPath = $env:IsoDrivePath
51+
Verbose = $true
52+
ErrorAction = 'Stop'
53+
Force = $true
54+
}
55+
56+
$null = Repair-SqlDscServer @repairSqlDscServerParameters
57+
}
58+
59+
It 'Should still have the named instance SQL Server service running after repair' {
60+
$getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop'
61+
62+
$getServiceResult | Should -Not -BeNullOrEmpty
63+
$getServiceResult.Status | Should -Be 'Running'
64+
}
65+
66+
It 'Should be able to connect to the instance after repair' {
67+
$sqlAdministratorUserName = 'SqlAdmin'
68+
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
69+
70+
$connectSqlDscDatabaseEngineParameters = @{
71+
InstanceName = 'DSCSQLTEST'
72+
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
73+
ErrorAction = 'Stop'
74+
}
75+
76+
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
77+
78+
$sqlServerObject | Should -Not -BeNullOrEmpty
79+
$sqlServerObject.InstanceName | Should -Be 'DSCSQLTEST'
80+
81+
Disconnect-SqlDscDatabaseEngine -ServerObject $sqlServerObject -ErrorAction 'Stop'
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)