Skip to content

Commit bde0611

Browse files
committed
Refactor tests in Get-SqlDscStartupParameter to simplify type checks for output properties and enhance clarity
1 parent 87409d8 commit bde0611

File tree

1 file changed

+19
-41
lines changed

1 file changed

+19
-41
lines changed

tests/Integration/Commands/Get-SqlDscStartupParameter.Integration.Tests.ps1

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -134,69 +134,47 @@ Describe 'Get-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration
134134

135135
It 'Should return an object with expected DataFilePath property' {
136136
$script:result.DataFilePath | Should -Not -BeNullOrEmpty
137-
# PowerShell unwraps single-element arrays to scalars, so we need to handle both cases
138-
if ($script:result.DataFilePath -is [System.Array]) {
139-
$script:result.DataFilePath | Should -BeOfType ([System.String[]])
140-
$script:result.DataFilePath[0] | Should -Match '\.mdf$'
141-
} else {
142-
$script:result.DataFilePath | Should -BeOfType ([System.String])
143-
$script:result.DataFilePath | Should -Match '\.mdf$'
144-
}
137+
$script:result.DataFilePath | Should -BeOfType ([System.String])
138+
$script:result.DataFilePath | Should -Match '\.mdf$'
145139
}
146140

147141
It 'Should return an object with expected LogFilePath property' {
148142
$script:result.LogFilePath | Should -Not -BeNullOrEmpty
149-
# PowerShell unwraps single-element arrays to scalars, so we need to handle both cases
150-
if ($script:result.LogFilePath -is [System.Array]) {
151-
$script:result.LogFilePath | Should -BeOfType ([System.String[]])
152-
$script:result.LogFilePath[0] | Should -Match '\.ldf$'
153-
} else {
154-
$script:result.LogFilePath | Should -BeOfType ([System.String])
155-
$script:result.LogFilePath | Should -Match '\.ldf$'
156-
}
143+
$script:result.LogFilePath | Should -BeOfType ([System.String])
144+
$script:result.LogFilePath | Should -Match '\.ldf$'
157145
}
158146

159147
It 'Should return an object with expected ErrorLogPath property' {
160148
$script:result.ErrorLogPath | Should -Not -BeNullOrEmpty
161-
# PowerShell unwraps single-element arrays to scalars, so we need to handle both cases
162-
if ($script:result.ErrorLogPath -is [System.Array]) {
163-
$script:result.ErrorLogPath | Should -BeOfType ([System.String[]])
164-
$script:result.ErrorLogPath[0] | Should -Match 'ERRORLOG$'
165-
} else {
166-
$script:result.ErrorLogPath | Should -BeOfType ([System.String])
167-
$script:result.ErrorLogPath | Should -Match 'ERRORLOG$'
168-
}
149+
$script:result.ErrorLogPath | Should -BeOfType ([System.String])
150+
$script:result.ErrorLogPath | Should -Match 'ERRORLOG$'
169151
}
170152

171-
It 'Should return TraceFlag property as an array or single value' {
172-
# PowerShell unwraps single-element arrays to scalars, so we need to handle both cases
173-
if ($script:result.TraceFlag -is [System.Array]) {
174-
$script:result.TraceFlag | Should -BeOfType ([System.UInt32[]])
175-
} elseif ($script:result.TraceFlag -ne $null) {
176-
$script:result.TraceFlag | Should -BeOfType ([System.UInt32])
153+
It 'Should return TraceFlag property as expected type' {
154+
# TraceFlag can be null, a single UInt32, or an array
155+
if ($null -ne $script:result.TraceFlag) {
156+
# Check if it's either a single UInt32 or UInt32 array
157+
($script:result.TraceFlag -is [System.UInt32]) -or ($script:result.TraceFlag -is [System.UInt32[]]) | Should -BeTrue -Because 'TraceFlag can be a single value or array depending on how many flags are set'
177158
} else {
178-
# TraceFlag can be empty/null if no trace flags are set
179-
$script:result.TraceFlag | Should -BeNullOrEmpty
159+
$script:result.TraceFlag | Should -BeNullOrEmpty -Because 'TraceFlag can be empty/null if no trace flags are set'
180160
}
181161
}
182162

183-
It 'Should return InternalTraceFlag property as an array or single value' {
184-
# PowerShell unwraps single-element arrays to scalars, so we need to handle both cases
185-
if ($script:result.InternalTraceFlag -is [System.Array]) {
186-
$script:result.InternalTraceFlag | Should -BeOfType ([System.UInt32[]])
187-
} elseif ($script:result.InternalTraceFlag -ne $null) {
188-
$script:result.InternalTraceFlag | Should -BeOfType ([System.UInt32])
163+
It 'Should return InternalTraceFlag property as expected type' {
164+
# InternalTraceFlag can be null, a single UInt32, or an array
165+
if ($null -ne $script:result.InternalTraceFlag) {
166+
# Check if it's either a single UInt32 or UInt32 array
167+
($script:result.InternalTraceFlag -is [System.UInt32]) -or ($script:result.InternalTraceFlag -is [System.UInt32[]]) | Should -BeTrue -Because 'InternalTraceFlag can be a single value or array depending on how many flags are set'
189168
} else {
190-
# InternalTraceFlag can be empty/null if no internal trace flags are set
191-
$script:result.InternalTraceFlag | Should -BeNullOrEmpty
169+
$script:result.InternalTraceFlag | Should -BeNullOrEmpty -Because 'InternalTraceFlag can be empty/null if no internal trace flags are set'
192170
}
193171
}
194172
}
195173

196174
Context 'When comparing results from different parameter sets' {
197175
It 'Should return the same results for ByServerName and ByServiceObject parameter sets' {
198176
$resultByServerName = Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop'
199-
177+
200178
$serviceObject = Get-SqlDscManagedComputerService -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ServiceType 'DatabaseEngine' -ErrorAction 'Stop'
201179
$resultByServiceObject = Get-SqlDscStartupParameter -ServiceObject $serviceObject -ErrorAction 'Stop'
202180

0 commit comments

Comments
 (0)