This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 374
/
mock_hypervisor_test.go
98 lines (73 loc) · 2.03 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
94
95
96
97
98
// Copyright (c) 2016 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMockHypervisorCreateSandbox(t *testing.T) {
var m *mockHypervisor
assert := assert.New(t)
sandbox := &Sandbox{
config: &SandboxConfig{
ID: "mock_sandbox",
HypervisorConfig: HypervisorConfig{
KernelPath: "",
ImagePath: "",
HypervisorPath: "",
},
},
}
ctx := context.Background()
// wrong config
err := m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
assert.Error(err)
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),
}
err = m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
assert.NoError(err)
}
func TestMockHypervisorStartSandbox(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.startSandbox(vmStartTimeout))
}
func TestMockHypervisorStopSandbox(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.stopSandbox())
}
func TestMockHypervisorAddDevice(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.addDevice(nil, imgDev))
}
func TestMockHypervisorGetSandboxConsole(t *testing.T) {
var m *mockHypervisor
expected := ""
result, err := m.getSandboxConsole("testSandboxID")
assert.NoError(t, err)
assert.Equal(t, result, expected)
}
func TestMockHypervisorSaveSandbox(t *testing.T) {
var m *mockHypervisor
assert.NoError(t, m.saveSandbox())
}
func TestMockHypervisorDisconnect(t *testing.T) {
var m *mockHypervisor
m.disconnect()
}
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", true)
assert.NoError(t, err)
assert.NotNil(t, i)
}