forked from adamlaska/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvtx_test.go
More file actions
72 lines (57 loc) · 1.74 KB
/
vtx_test.go
File metadata and controls
72 lines (57 loc) · 1.74 KB
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
package virtualbox
import (
"testing"
"errors"
"github.com/stretchr/testify/assert"
)
type MockLogsReader struct {
content []string
err error
}
func (r *MockLogsReader) Read(path string) ([]string, error) {
return r.content, r.err
}
func TestIsVTXEnabledInTheVM(t *testing.T) {
driver := NewDriver("default", "path")
var tests = []struct {
description string
content []string
err error
}{
{"Empty log", []string{}, nil},
{"Raw mode", []string{"Falling back to raw-mode: VT-x is disabled in the BIOS for all CPU modes"}, nil},
{"Raw mode", []string{"HM: HMR3Init: Falling back to raw-mode: VT-x is not available"}, nil},
}
for _, test := range tests {
driver.logsReader = &MockLogsReader{
content: test.content,
err: test.err,
}
disabled, err := driver.IsVTXDisabledInTheVM()
assert.False(t, disabled, test.description)
assert.Equal(t, test.err, err)
}
}
func TestIsVTXDisabledInTheVM(t *testing.T) {
driver := NewDriver("default", "path")
var tests = []struct {
description string
content []string
err error
}{
{"VT-x Disabled", []string{"VT-x is disabled"}, nil},
{"No HW virtualization", []string{"the host CPU does NOT support HW virtualization"}, nil},
{"Unable to start VM", []string{"VERR_VMX_UNABLE_TO_START_VM"}, nil},
{"Power up failed", []string{"00:00:00.318604 Power up failed (vrc=VERR_VMX_NO_VMX, rc=NS_ERROR_FAILURE (0X80004005))"}, nil},
{"Unable to read log", nil, errors.New("Unable to read log")},
}
for _, test := range tests {
driver.logsReader = &MockLogsReader{
content: test.content,
err: test.err,
}
disabled, err := driver.IsVTXDisabledInTheVM()
assert.True(t, disabled, test.description)
assert.Equal(t, test.err, err)
}
}