Skip to content

Commit 72ac4ca

Browse files
author
Shreyansh Sancheti
committed
service: add unit tests for LCOW v2 shim service layer
Add unit tests for the sandbox, shimdiag, and task service methods in cmd/containerd-shim-lcow-v2/service/. Tests exercise the public TTRPC methods directly — including the instrumentation layer — with a mocked vm.Controller injected via export_test.go. The mock is generated from the vm.Controller interface using mockgen and lives at internal/controller/vm/mock/mock_vm.go. A go:generate directive is added to internal/controller/vm/interface.go. 14 test functions, 57 subtests covering: sandbox ID mismatch guards across 7 methods, duplicate sandbox rejection, missing config.json, StartVM success and failure, platform state gating, StopSandbox terminate paths, WaitSandbox exit code mapping (clean vs ERROR_INTERNAL_ERROR) and Wait/ ExitStatus failures, SandboxStatus for all 5 VM states plus ExitStatus error, ShutdownSandbox terminate-error-swallowing, SandboxMetrics marshal roundtrip, DiagExecInHost delegation, DiagPid, and ErrNotImplemented coverage for all 20 stub methods. Not covered: the full CreateSandbox -> BuildSandboxConfig -> CreateVM path (BuildSandboxConfig has its own tests in internal/builder/vm/lcow/) and the confidential StartSandbox path (reads boot files from disk — belongs in functional tests). All tests run without admin privileges or HCS. Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
1 parent 372f3f6 commit 72ac4ca

6 files changed

Lines changed: 1034 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build windows
2+
3+
package service
4+
5+
import (
6+
"github.com/Microsoft/hcsshim/internal/builder/vm/lcow"
7+
"github.com/Microsoft/hcsshim/internal/controller/vm"
8+
9+
"github.com/containerd/containerd/v2/pkg/shutdown"
10+
)
11+
12+
func SetSandboxIDForTest(s *Service, id string) {
13+
s.sandboxID = id
14+
}
15+
16+
func SetSandboxOptionsForTest(s *Service, opts *lcow.SandboxOptions) {
17+
s.sandboxOptions = opts
18+
}
19+
20+
func NewTestService(ctrl vm.Controller, sd shutdown.Service) *Service {
21+
return &Service{
22+
vmController: ctrl,
23+
events: make(chan interface{}, 128),
24+
shutdown: sd,
25+
}
26+
}

0 commit comments

Comments
 (0)