Skip to content

Commit

Permalink
clh: add startSandbox unit test
Browse files Browse the repository at this point in the history
- use utils.StartCmd to mock call to start hypervisor process.

- Add unit test for startSandbox.

Fixes: kata-containers#2367

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
  • Loading branch information
jcvenegas committed Dec 19, 2019
1 parent 70ba55d commit dc88d27
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ func (clh *cloudHypervisor) LaunchClh() (string, int, error) {
cmd.Env = append(cmd.Env, "RUST_BACKTRACE=full")
}

if err := cmd.Start(); err != nil {
if err := utils.StartCmd(cmd); err != nil {
fmt.Println("Error starting cloudHypervisor", err)
if cmd.Process != nil {
cmd.Process.Kill()
Expand Down
31 changes: 31 additions & 0 deletions virtcontainers/clh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,34 @@ func TestClhCreateSandbox(t *testing.T) {
assert.NoError(os.RemoveAll(parentDir))
assert.Exactly(clhConfig, clh.config)
}

func TestClooudHypervisorStartSandbox(t *testing.T) {
assert := assert.New(t)
clhConfig, err := newClhConfig()

clh := &cloudHypervisor{
config: clhConfig,
APIClient: &clhClientMock{},
virtiofsd: &virtiofsdMock{},
}

sandbox := &Sandbox{
ctx: context.Background(),
id: "testSandbox",
config: &SandboxConfig{
HypervisorConfig: clhConfig,
},
}

vcStore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id)
assert.NoError(err)

sandbox.store = vcStore

// Create parent dir path for hypervisor.json
parentDir := store.SandboxConfigurationRootPath(sandbox.id)
assert.NoError(os.MkdirAll(parentDir, store.DirMode))

err = clh.startSandbox(10)
assert.NoError(err)
}

0 comments on commit dc88d27

Please sign in to comment.