Files
kata-containers/virtcontainers/mock_hypervisor_test.go
Samuel Ortiz fad23ea54e virtcontainers: Conversion to Stores
We convert the whole virtcontainers code to use the store package
instead of the resource_storage one. The resource_storage removal will
happen in a separate change for a more logical split.

This change is fairly big but mostly does not change the code logic.
What really changes is when we create a store for a container or a
sandbox. We now need to explictly do so instead of just assigning a
filesystem{} instance. Other than that, the logic is kept intact.

Fixes: #1099

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-02-07 00:59:29 +01:00

98 lines
1.8 KiB
Go

// Copyright (c) 2016 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"context"
"fmt"
"testing"
)
func TestMockHypervisorCreateSandbox(t *testing.T) {
var m *mockHypervisor
sandbox := &Sandbox{
config: &SandboxConfig{
ID: "mock_sandbox",
HypervisorConfig: HypervisorConfig{
KernelPath: "",
ImagePath: "",
HypervisorPath: "",
},
},
}
ctx := context.Background()
// wrong config
if err := m.createSandbox(ctx, sandbox.config.ID, &sandbox.config.HypervisorConfig, nil); 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),
}
if err := m.createSandbox(ctx, sandbox.config.ID, &sandbox.config.HypervisorConfig, nil); err != nil {
t.Fatal(err)
}
}
func TestMockHypervisorStartSandbox(t *testing.T) {
var m *mockHypervisor
if err := m.startSandbox(vmStartTimeout); 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()
}