-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapi_test.go
50 lines (40 loc) · 1.08 KB
/
api_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
package vmx
import (
"io/ioutil"
"path/filepath"
"testing"
)
func TestFindDevice(t *testing.T) {
data, err := ioutil.ReadFile(filepath.Join(".", "fixtures", "b.vmx"))
ok(t, err)
vm := new(VirtualMachine)
err = Unmarshal([]byte(data), vm)
// Test finding all devices on all controllers
expectedDevices := 5
devicesFound := 0
vm.FindDevice(func(d Device) bool {
devicesFound++
return false
})
assert(t, devicesFound == expectedDevices, "%d != %d", devicesFound, expectedDevices)
// Test finding one device
ID := "ide1:0"
var device Device
vm.FindDevice(func(d Device) bool {
if d.VMXID == ID {
device = d
return true
}
return false
})
assert(t, device.VMXID == ID, "%s != %s", device.VMXID, ID)
assert(t, device.Type == CDROM_IMAGE, "%s != %s", device.Type, CDROM_IMAGE)
// Test finding devices from a specific controller
expectedSCSIDevices := 3
foundSCSIDevices := 0
vm.FindDevice(func(d Device) bool {
foundSCSIDevices++
return false
}, SCSI)
assert(t, expectedSCSIDevices == foundSCSIDevices, "%d != %d", expectedSCSIDevices, foundSCSIDevices)
}