Skip to content

Commit 3cb8f9d

Browse files
committed
feat(#133): enhance test coverage for NovaModuleTools
- Add tests for CodeScene Cobertura remapping helpers - Implement coverage gap tests for quality helpers - Validate Nova package output directory initialization - Improve timeout handling in PowerShell script execution
1 parent 75fcdb5 commit 3cb8f9d

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

tests/UpdateNotification.TestSupport.ps1

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,105 @@ function Invoke-TestNovaSelfUpdate {
180180
}
181181
}
182182
}
183+
184+
function New-TestPowerShellRunnerState {
185+
[CmdletBinding()]
186+
param()
187+
188+
return [pscustomobject]@{
189+
Script = $null
190+
Arguments = [System.Collections.Generic.List[object]]::new()
191+
LastTimeoutMilliseconds = $null
192+
StopCalls = 0
193+
EndInvokeCalls = 0
194+
DisposeCalls = 0
195+
}
196+
}
197+
198+
function New-TestPowerShellWaitHandle {
199+
[CmdletBinding()]
200+
param(
201+
[Parameter(Mandatory)][object]$State,
202+
[Parameter(Mandatory)][bool]$ShouldComplete
203+
)
204+
205+
$waitHandle = [pscustomobject]@{
206+
ShouldComplete = $ShouldComplete
207+
State = $State
208+
}
209+
210+
$waitHandle | Add-Member -MemberType ScriptMethod -Name WaitOne -Value {
211+
param($TimeoutMilliseconds)
212+
213+
$this.State.LastTimeoutMilliseconds = $TimeoutMilliseconds
214+
return $this.ShouldComplete
215+
}
216+
217+
return $waitHandle
218+
}
219+
220+
function Add-TestPowerShellRunnerMethods {
221+
[CmdletBinding()]
222+
param(
223+
[Parameter(Mandatory)][object]$Runner
224+
)
225+
226+
$runner | Add-Member -MemberType ScriptMethod -Name AddScript -Value {
227+
param($ScriptText)
228+
229+
$this.State.Script = $ScriptText
230+
return $this
231+
}
232+
$runner | Add-Member -MemberType ScriptMethod -Name AddArgument -Value {
233+
param($Argument)
234+
235+
$this.State.Arguments.Add($Argument) | Out-Null
236+
return $this
237+
}
238+
$runner | Add-Member -MemberType ScriptMethod -Name BeginInvoke -Value {
239+
return $this.AsyncResult
240+
}
241+
$runner | Add-Member -MemberType ScriptMethod -Name Stop -Value {
242+
$this.State.StopCalls++
243+
if ($this.ThrowOnStop) {
244+
throw 'stop failed'
245+
}
246+
}
247+
$runner | Add-Member -MemberType ScriptMethod -Name EndInvoke -Value {
248+
param($InvocationResult)
249+
250+
$this.State.EndInvokeCalls++
251+
if ($this.ThrowOnEndInvoke) {
252+
throw 'end failed'
253+
}
254+
255+
return $this.EndInvokeResult
256+
}
257+
$runner | Add-Member -MemberType ScriptMethod -Name Dispose -Value {
258+
$this.State.DisposeCalls++
259+
}
260+
261+
return $Runner
262+
}
263+
264+
function New-TestPowerShellRunner {
265+
[CmdletBinding()]
266+
param(
267+
[bool]$ShouldComplete,
268+
[object]$EndInvokeResult = $null,
269+
[switch]$ThrowOnStop,
270+
[switch]$ThrowOnEndInvoke
271+
)
272+
273+
$state = New-TestPowerShellRunnerState
274+
$waitHandle = New-TestPowerShellWaitHandle -State $state -ShouldComplete $ShouldComplete
275+
$runner = [pscustomobject]@{
276+
State = $state
277+
AsyncResult = [pscustomobject]@{AsyncWaitHandle = $waitHandle}
278+
EndInvokeResult = $EndInvokeResult
279+
ThrowOnStop = $ThrowOnStop.IsPresent
280+
ThrowOnEndInvoke = $ThrowOnEndInvoke.IsPresent
281+
}
282+
283+
return Add-TestPowerShellRunnerMethods -Runner $runner
284+
}

0 commit comments

Comments
 (0)