Skip to content

Commit 65d6176

Browse files
committed
Improve commands and tests
1 parent 827cd5a commit 65d6176

6 files changed

Lines changed: 109 additions & 7 deletions

File tree

source/Private/Invoke-SetupAction.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ function Invoke-SetupAction
694694

695695
[Parameter(ParameterSetName = 'Install')]
696696
[Parameter(ParameterSetName = 'InstallRole')]
697+
[Parameter(ParameterSetName = 'PrepareImage')]
697698
[Parameter(ParameterSetName = 'InstallFailoverCluster')]
698699
[Parameter(ParameterSetName = 'PrepareFailoverCluster')]
699700
[System.String]

source/Public/Install-SqlDscServer.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ function Install-SqlDscServer
567567

568568
[Parameter(ParameterSetName = 'Install')]
569569
[Parameter(ParameterSetName = 'InstallRole')]
570+
[Parameter(ParameterSetName = 'PrepareImage')]
570571
[Parameter(ParameterSetName = 'InstallFailoverCluster')]
571572
[Parameter(ParameterSetName = 'PrepareFailoverCluster')]
572573
[System.String]

tests/Integration/Commands/Complete-SqlDscImage.Integration.Tests.ps1

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,32 @@ Describe 'Complete-SqlDscImage' -Tag @('Integration_SQL2017', 'Integration_SQL20
4949
Force = $true
5050
}
5151

52-
$null = Complete-SqlDscImage @completeSqlDscImageParameters
52+
try
53+
{
54+
$null = Complete-SqlDscImage @completeSqlDscImageParameters
55+
}
56+
catch
57+
{
58+
# Output Summary.txt if it exists to help diagnose the failure
59+
$summaryFiles = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server' -Filter 'Summary.txt' -Recurse -ErrorAction SilentlyContinue |
60+
Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } |
61+
Sort-Object -Property LastWriteTime -Descending |
62+
Select-Object -First 1
63+
64+
if ($summaryFiles)
65+
{
66+
Write-Verbose "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====" -Verbose
67+
Get-Content -Path $summaryFiles.FullName | Write-Verbose -Verbose
68+
Write-Verbose "==== End of Summary.txt ====" -Verbose
69+
}
70+
else
71+
{
72+
Write-Verbose 'No Summary.txt file found.' -Verbose
73+
}
74+
75+
# Re-throw the original error
76+
throw $_
77+
}
5378
}
5479
}
5580

@@ -77,7 +102,32 @@ Describe 'Complete-SqlDscImage' -Tag @('Integration_SQL2017', 'Integration_SQL20
77102
Force = $true
78103
}
79104

80-
$null = Complete-SqlDscImage @completeSqlDscImageParameters
105+
try
106+
{
107+
$null = Complete-SqlDscImage @completeSqlDscImageParameters
108+
}
109+
catch
110+
{
111+
# Output Summary.txt if it exists to help diagnose the failure
112+
$summaryFiles = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server' -Filter 'Summary.txt' -Recurse -ErrorAction SilentlyContinue |
113+
Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } |
114+
Sort-Object -Property LastWriteTime -Descending |
115+
Select-Object -First 1
116+
117+
if ($summaryFiles)
118+
{
119+
Write-Verbose "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====" -Verbose
120+
Get-Content -Path $summaryFiles.FullName | Write-Verbose -Verbose
121+
Write-Verbose "==== End of Summary.txt ====" -Verbose
122+
}
123+
else
124+
{
125+
Write-Verbose 'No Summary.txt file found.' -Verbose
126+
}
127+
128+
# Re-throw the original error
129+
throw $_
130+
}
81131
}
82132
}
83133

@@ -101,7 +151,32 @@ Describe 'Complete-SqlDscImage' -Tag @('Integration_SQL2017', 'Integration_SQL20
101151
Force = $true
102152
}
103153

104-
$null = Complete-SqlDscImage @completeSqlDscImageParameters
154+
try
155+
{
156+
$null = Complete-SqlDscImage @completeSqlDscImageParameters
157+
}
158+
catch
159+
{
160+
# Output Summary.txt if it exists to help diagnose the failure
161+
$summaryFiles = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server' -Filter 'Summary.txt' -Recurse -ErrorAction SilentlyContinue |
162+
Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } |
163+
Sort-Object -Property LastWriteTime -Descending |
164+
Select-Object -First 1
165+
166+
if ($summaryFiles)
167+
{
168+
Write-Verbose "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====" -Verbose
169+
Get-Content -Path $summaryFiles.FullName | Write-Verbose -Verbose
170+
Write-Verbose "==== End of Summary.txt ====" -Verbose
171+
}
172+
else
173+
{
174+
Write-Verbose 'No Summary.txt file found.' -Verbose
175+
}
176+
177+
# Re-throw the original error
178+
throw $_
179+
}
105180
}
106181
}
107182
}

tests/Integration/Commands/Install-SqlDscServer.Integration.PrepareImage.Tests.ps1

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Describe 'Install-SqlDscServer - PrepareImage' -Tag @('Integration_SQL2017', 'In
4444
$installSqlDscServerParameters = @{
4545
PrepareImage = $true
4646
AcceptLicensingTerms = $true
47-
InstanceName = 'DSCSQLTEST'
47+
InstanceId = 'DSCSQLTEST'
4848
Features = 'SQLENGINE'
4949
InstallSharedDir = 'C:\Program Files\Microsoft SQL Server'
5050
InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server'
@@ -54,7 +54,32 @@ Describe 'Install-SqlDscServer - PrepareImage' -Tag @('Integration_SQL2017', 'In
5454
Force = $true
5555
}
5656

57-
$null = Install-SqlDscServer @installSqlDscServerParameters
57+
try
58+
{
59+
$null = Install-SqlDscServer @installSqlDscServerParameters
60+
}
61+
catch
62+
{
63+
# Output Summary.txt if it exists to help diagnose the failure
64+
$summaryFiles = Get-ChildItem -Path 'C:\Program Files\Microsoft SQL Server' -Filter 'Summary.txt' -Recurse -ErrorAction SilentlyContinue |
65+
Where-Object { $_.FullName -match '\\Setup Bootstrap\\Log\\' } |
66+
Sort-Object -Property LastWriteTime -Descending |
67+
Select-Object -First 1
68+
69+
if ($summaryFiles)
70+
{
71+
Write-Verbose "==== SQL Server Setup Summary.txt (from $($summaryFiles.FullName)) ====" -Verbose
72+
Get-Content -Path $summaryFiles.FullName | Write-Verbose -Verbose
73+
Write-Verbose "==== End of Summary.txt ====" -Verbose
74+
}
75+
else
76+
{
77+
Write-Verbose 'No Summary.txt file found.' -Verbose
78+
}
79+
80+
# Re-throw the original error
81+
throw $_
82+
}
5883
}
5984
}
6085
}

tests/Unit/Private/Invoke-SetupAction.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' {
7777
@{
7878
MockParameterSetName = 'PrepareImage'
7979
# cSpell: disable-next
80-
MockExpectedParameters = '-PrepareImage -AcceptLicensingTerms -MediaPath <string> -Features <string[]> -InstanceId <string> [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource <string>] [-InstallSharedDir <string>] [-InstanceDir <string>] [-PBEngSvcAccount <string>] [-PBEngSvcPassword <securestring>] [-PBEngSvcStartupType <string>] [-PBStartPortRange <ushort>] [-PBEndPortRange <ushort>] [-PBScaleOut] [-Timeout <uint>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]'
80+
MockExpectedParameters = '-PrepareImage -AcceptLicensingTerms -MediaPath <string> -Features <string[]> -InstanceId <string> [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource <string>] [-InstallSharedDir <string>] [-InstallSharedWowDir <string>] [-InstanceDir <string>] [-PBEngSvcAccount <string>] [-PBEngSvcPassword <securestring>] [-PBEngSvcStartupType <string>] [-PBStartPortRange <ushort>] [-PBEndPortRange <ushort>] [-PBScaleOut] [-Timeout <uint>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]'
8181
}
8282
@{
8383
MockParameterSetName = 'CompleteImage'

tests/Unit/Public/Install-SqlDscServer.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' {
7272
@{
7373
MockParameterSetName = 'PrepareImage'
7474
# cSpell: disable-next
75-
MockExpectedParameters = '-PrepareImage -AcceptLicensingTerms -MediaPath <string> -Features <string[]> -InstanceId <string> [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource <string>] [-InstallSharedDir <string>] [-InstanceDir <string>] [-PBEngSvcAccount <string>] [-PBEngSvcPassword <securestring>] [-PBEngSvcStartupType <string>] [-PBStartPortRange <ushort>] [-PBEndPortRange <ushort>] [-PBScaleOut] [-Timeout <uint>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]'
75+
MockExpectedParameters = '-PrepareImage -AcceptLicensingTerms -MediaPath <string> -Features <string[]> -InstanceId <string> [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource <string>] [-InstallSharedDir <string>] [-InstallSharedWowDir <string>] [-InstanceDir <string>] [-PBEngSvcAccount <string>] [-PBEngSvcPassword <securestring>] [-PBEngSvcStartupType <string>] [-PBStartPortRange <ushort>] [-PBEndPortRange <ushort>] [-PBScaleOut] [-Timeout <uint>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]'
7676
}
7777
@{
7878
MockParameterSetName = 'Upgrade'

0 commit comments

Comments
 (0)