@@ -162,7 +162,7 @@ Describe "ContainerdTools.psm1" {
162162
163163 Context " Register-ContainerdService" - Tag " Register-ContainerdService" {
164164 BeforeAll {
165- $MockContainerdPath = ' TestDrive: \Program Files\Containerd'
165+ $MockContainerdPath = " $ TestDrive \Program Files\Containerd"
166166 # New-Item -Path $MockContainerdPath -ItemType 'Directory' -Force | Out-Null
167167 New-Item - Path " $MockContainerdPath \bin\containerd.exe" - ItemType ' File' - Force | Out-Null
168168
@@ -172,15 +172,19 @@ Describe "ContainerdTools.psm1" {
172172 Mock Get-DefaultInstallPath - ModuleName " ContainerdTools" `
173173 - MockWith { return $MockContainerdPath } `
174174 - ParameterFilter { $Tool -eq " Containerd" }
175- Mock Invoke-ExecutableCommand - ModuleName " ContainerdTools" `
176- - ParameterFilter { $Arguments -eq " config default" } `
177- - MockWith { return ' Sample containerd default config data' }
178175
179- $obj = New-MockObject - Type ' System.Diagnostics.Process' - Properties @ { ExitCode = 0 }
180- Mock Invoke-ExecutableCommand - ModuleName " ContainerdTools" - MockWith { return $obj }
176+ $mockProcess = New-MockObject - Type ' System.Diagnostics.Process' - Properties @ { ExitCode = 0 }
177+ Mock Invoke-ExecutableCommand - ModuleName " ContainerdTools" - MockWith { return $mockProcess }
181178
182- # $MockService = New-MockObject -Type System.ServiceProcess.ServiceController -Methods @{ WaitForStatus = { } }
183- # Mock Get-Service -ModuleName "ContainerdTools" -MockWith { return $MockService }
179+ # Mock for default config
180+ $mockConfigStdOut = New-MockObject - Type ' System.IO.StreamReader' - Methods @ { ReadToEnd = { return " Sample containerd default config data" } }
181+ $mockConfigProcess = New-MockObject - Type ' System.Diagnostics.Process' - Properties @ {
182+ StandardOutput = $mockConfigStdOut
183+ }
184+ Mock Invoke-ExecutableCommand - ModuleName " ContainerdTools" `
185+ - ParameterFilter { $Arguments -eq " config default" } `
186+ - MockWith { return $mockConfigProcess }
187+
184188 Mock Get-Service - ModuleName " ContainerdTools" - MockWith { return [MockService ]::new(' Containerd' ) }
185189 Mock Set-Service - ModuleName " ContainerdTools"
186190 Mock Start-ContainerdService - ModuleName " ContainerdTools"
@@ -254,6 +258,19 @@ Describe "ContainerdTools.psm1" {
254258
255259 { Register-ContainerdService - Force } | Should - Throw " Failed to register containerd service.*"
256260 }
261+
262+ It " Should throw an error if config file is empty" {
263+ # Mock for default config
264+ $mockConfigStdOut = New-MockObject - Type ' System.IO.StreamReader' - Methods @ { ReadToEnd = { return } }
265+ $mockConfigProcess = New-MockObject - Type ' System.Diagnostics.Process' - Properties @ {
266+ StandardOutput = $mockConfigStdOut
267+ }
268+ Mock Invoke-ExecutableCommand - ModuleName " ContainerdTools" `
269+ - ParameterFilter { $Arguments -eq " config default" } `
270+ - MockWith { return $mockConfigProcess }
271+
272+ { Register-ContainerdService - Force } | Should - Throw " Config file is empty. '$MockContainerdPath \config.toml'"
273+ }
257274 }
258275
259276 Context " Uninstall-Containerd" - Tag " Uninstall-Containerd" {
0 commit comments