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 20, 2019
1 parent e0bd840 commit 692885f
Show file tree
Hide file tree
Showing 2 changed files with 33 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 @@ -756,7 +756,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
32 changes: 32 additions & 0 deletions virtcontainers/clh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,35 @@ 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()
assert.NoError(err)

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 692885f

Please sign in to comment.