forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_hypervisor_test.go
93 lines (69 loc) · 1.94 KB
/
mock_hypervisor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2016 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMockHypervisorCreateVM(t *testing.T) {
m := &mockHypervisor{}
assert := assert.New(t)
sandbox := &Sandbox{
config: &SandboxConfig{
ID: "mock_sandbox",
HypervisorConfig: HypervisorConfig{
KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel),
ImagePath: fmt.Sprintf("%s/%s", testDir, testImage),
HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor),
},
},
}
network, err := NewNetwork()
assert.NoError(err)
ctx := context.Background()
err = m.CreateVM(ctx, sandbox.config.ID, network, &sandbox.config.HypervisorConfig)
assert.NoError(err)
}
func TestMockHypervisorStartSandbox(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.StartVM(context.Background(), VmStartTimeout))
}
func TestMockHypervisorStopSandbox(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.StopVM(context.Background(), false))
}
func TestMockHypervisorAddDevice(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.AddDevice(context.Background(), nil, ImgDev))
}
func TestMockHypervisorGetSandboxConsole(t *testing.T) {
var m *mockHypervisor
expected := ""
expectedProto := ""
proto, result, err := m.GetVMConsole(context.Background(), "testSandboxID")
assert.NoError(t, err)
assert.Equal(t, result, expected)
assert.Equal(t, proto, expectedProto)
}
func TestMockHypervisorSaveSandbox(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.SaveVM())
}
func TestMockHypervisorDisconnect(t *testing.T) {
var m *mockHypervisor
m.Disconnect(context.Background())
}
func TestMockHypervisorCheck(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.Check())
}
func TestMockGenerateSocket(t *testing.T) {
var m *mockHypervisor
i, err := m.GenerateSocket("a")
assert.NoError(t, err)
assert.NotNil(t, i)
}