forked from project-machine/disko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirt_test.go
65 lines (56 loc) · 1.79 KB
/
virt_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
package linux
import (
"fmt"
"testing"
)
type myDetector struct {
out []byte
err []byte
rc int
expected virtType
logged string
}
func (d *myDetector) detectVirt() ([]byte, []byte, int) {
return d.out, d.err, d.rc
}
func (d *myDetector) logf(format string, a ...interface{}) {
d.logged = fmt.Sprintf(format, a...)
}
func TestVirtType(t *testing.T) {
tables := []myDetector{
{[]byte("none\n"), []byte{}, 1, virtNone, ""},
{[]byte("unknown\n"), []byte{}, 0, virtUnknown, ""},
{[]byte("none\n"), []byte{}, 0, virtNone, ""},
{[]byte("kvm\n"), []byte{}, 0, virtKvm, ""},
{[]byte("error\n"), []byte{}, 0, virtError, ""},
{[]byte("qemu\n"), []byte{}, 0, virtQemu, ""},
{[]byte("zvm\n"), []byte{}, 0, virtZvm, ""},
{[]byte("vmware\n"), []byte{}, 0, virtVmware, ""},
{[]byte("microsoft\n"), []byte{}, 0, virtMicrosoft, ""},
{[]byte("oracle\n"), []byte{}, 0, virtOracle, ""},
{[]byte("xen\n"), []byte{}, 0, virtXen, ""},
{[]byte("bochs\n"), []byte{}, 0, virtBochs, ""},
{[]byte("uml\n"), []byte{}, 0, virtUml, ""},
{[]byte("parallels\n"), []byte{}, 0, virtParallels, ""},
{[]byte("bhyve\n"), []byte{}, 0, virtBhyve, ""},
{[]byte("not-known-yet\n"), []byte{}, 0, virtUnknown, ""},
{[]byte("unexpected\n"), []byte("error"), 3, virtError, ""},
}
for _, td := range tables {
// set it back to unset so cache is not used.
systemVirtType = virtUnset
td := td
found := getVirtTypeIface(&td)
if found != td.expected {
t.Errorf("out=%s err=%s rc=%d returned %d (%s) expected %s",
td.out, td.err, td.rc,
found, found.String(), td.expected.String())
}
}
systemVirtType = virtOracle
found := getVirtType()
if found != virtOracle {
t.Errorf("value not cached in systemVirtType. found %s expected %s\n",
fmt.Sprint(found), fmt.Sprint(virtOracle))
}
}