@@ -28,20 +28,27 @@ Describe "BuildkitTools.psm1" {
2828 # Mock functions
2929 function Test-ServiceRegistered { }
3030 Mock Test-ServiceRegistered - ModuleName ' BuildkitTools' - MockWith { return $true }
31+
32+ function CleanupTestDrive {
33+ Get-ChildItem - Path " $TestDrive " - Force - ErrorAction SilentlyContinue | `
34+ Remove-Item - Recurse - Force - Confirm:$false - ErrorAction SilentlyContinue
35+ Get-ChildItem - Path " TestDrive:\" - Recurse - Force - ErrorAction SilentlyContinue | `
36+ Remove-Item - Recurse - Force - Confirm:$false - ErrorAction SilentlyContinue
37+ }
3138 }
3239
3340 BeforeEach {
34- Remove-Item - Path " $TestDrive " - Re - Force - ErrorAction Ignore
41+ CleanupTestDrive
3542 }
3643
3744 AfterEach {
3845 $ENV: PESTER = $false
39- Remove-Item - Path " $TestDrive " - Re - Force - ErrorAction Ignore
46+
47+ CleanupTestDrive
4048 }
4149
4250 AfterAll {
43- Remove-Module - Name " $ModuleParentPath \Private\CommonToolUtilities.psm1" - Force - ErrorAction Ignore
44- Remove-Module - Name " $ModuleParentPath \Public\BuildkitTools.psm1" - Force - ErrorAction Ignore
51+ CleanupTestDrive
4552 }
4653
4754 Context " Install-Buildkit" - Tag " Install-Buildkit" {
@@ -63,7 +70,7 @@ Describe "BuildkitTools.psm1" {
6370 }
6471
6572 AfterEach {
66- Remove-Item - Path " TestDrive:\ " - Force - ErrorAction Ignore
73+ CleanupTestDrive
6774 }
6875
6976 It ' Should not process on implicit request for validation (WhatIfPreference)' {
@@ -130,10 +137,10 @@ Describe "BuildkitTools.psm1" {
130137
131138 Should - Invoke Register-BuildkitdService - Times 1 - Exactly - Scope It - ModuleName ' BuildkitTools' `
132139 - ParameterFilter {
133- $BuildKitPath -eq " $Env: ProgramFiles \Buildkit" -and
134- $WinCNIPath -eq " $ENV: ProgramFiles \Containerd\cni"
135- $Start -eq $true
136- }
140+ $BuildKitPath -eq " $Env: ProgramFiles \Buildkit" -and
141+ $WinCNIPath -eq " $ENV: ProgramFiles \Containerd\cni"
142+ $Start -eq $true
143+ }
137144 }
138145
139146 It " Should uninstall tool if it is already installed" {
@@ -222,7 +229,6 @@ Describe "BuildkitTools.psm1" {
222229
223230 $expectedExecutablePath = " $MockBuildKitPath \bin\buildkitd.exe"
224231 $expectedCommandArguments = " --register-service --debug --containerd-worker=true --containerd-cni-config-path=`" $MockCniConfPath `" --containerd-cni-binary-dir=`" $MockCniBinDir `" --service-name buildkitd"
225- Write-Host " '$expectedCommandArguments '" - ForegroundColor Magenta
226232 Should - Invoke Invoke-ExecutableCommand - Times 1 - Scope It - ModuleName " BuildkitTools" `
227233 - ParameterFilter {
228234 ($Executable -eq $expectedExecutablePath ) -and
0 commit comments