mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-24 01:24:26 +01:00
For each time a sandbox structure is created, we ensure s.Release() is called. Then we can keep the qmp connection as long as Sandbox pointer is alive. All VC interfaces are still stateless as s.Release() is called before each API returns. OTOH, for VCSandbox APIs, FetchSandbox() must be paired with s.Release, the same as before. Fixes: #500 Signed-off-by: Peng Tao <bergwolf@gmail.com>
113 lines
2.1 KiB
Go
113 lines
2.1 KiB
Go
// Copyright (c) 2016 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package virtcontainers
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestMockHypervisorInit(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
sandbox := &Sandbox{
|
|
config: &SandboxConfig{
|
|
ID: "mock_sandbox",
|
|
HypervisorConfig: HypervisorConfig{
|
|
KernelPath: "",
|
|
ImagePath: "",
|
|
HypervisorPath: "",
|
|
},
|
|
},
|
|
storage: &filesystem{},
|
|
}
|
|
|
|
// wrong config
|
|
if err := m.init(sandbox.config.ID, &sandbox.config.HypervisorConfig, sandbox.config.VMConfig, sandbox.storage); err == nil {
|
|
t.Fatal()
|
|
}
|
|
|
|
sandbox.config.HypervisorConfig = HypervisorConfig{
|
|
KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel),
|
|
ImagePath: fmt.Sprintf("%s/%s", testDir, testImage),
|
|
HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor),
|
|
}
|
|
|
|
// right config
|
|
if err := m.init(sandbox.config.ID, &sandbox.config.HypervisorConfig, sandbox.config.VMConfig, sandbox.storage); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorCreateSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
if err := m.createSandbox(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorStartSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
if err := m.startSandbox(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorWaitSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
if err := m.waitSandbox(0); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorStopSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
if err := m.stopSandbox(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorAddDevice(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
if err := m.addDevice(nil, imgDev); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorGetSandboxConsole(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
expected := ""
|
|
|
|
result, err := m.getSandboxConsole("testSandboxID")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if result != expected {
|
|
t.Fatalf("Got %s\nExpecting %s", result, expected)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorSaveSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
if err := m.saveSandbox(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMockHypervisorDisconnect(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
m.disconnect()
|
|
}
|