forked from terra-farm/go-virtualbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
machine_test.go
93 lines (84 loc) · 2.42 KB
/
machine_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
package virtualbox
import (
"context"
"errors"
"testing"
"github.com/go-test/deep"
)
var (
testUbuntuMachine = &Machine{
Name: "Ubuntu",
Firmware: "BIOS",
UUID: "37f5d336-bf07-48dd-947c-37e6a56420a7",
State: Saved,
CPUs: 1,
Memory: 1024, VRAM: 8, CfgFile: "/Users/fix/VirtualBox VMs/go-virtualbox/go-virtualbox.vbox",
BaseFolder: "/Users/fix/VirtualBox VMs/go-virtualbox", OSType: "", Flag: 0, BootOrder: []string{},
NICs: []NIC{
{Network: "nat", Hardware: "82540EM", HostInterface: "", MacAddr: "080027EE1DF7"},
},
}
testGoVirtualboxMachine = &Machine{
Name: "go-virtualbox",
Firmware: "BIOS",
UUID: "37f5d336-bf08-48dd-947c-37e6a56420a7",
State: Saved,
CPUs: 1,
Memory: 1024, VRAM: 8, CfgFile: "/Users/fix/VirtualBox VMs/go-virtualbox/go-virtualbox.vbox",
BaseFolder: "/Users/fix/VirtualBox VMs/go-virtualbox", OSType: "", Flag: 0, BootOrder: []string{},
NICs: []NIC{
{Network: "nat", Hardware: "82540EM", HostInterface: "", MacAddr: "080027EE1DF7"},
},
}
)
func TestMachine(t *testing.T) {
testCases := map[string]struct {
in string
want *Machine
err error
}{
"by name": {
in: "Ubuntu",
want: testUbuntuMachine,
err: nil,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
m := newTestManager()
got, err := m.Machine(context.Background(), tc.in)
if diff := deep.Equal(got, tc.want); !errors.Is(err, tc.err) || diff != nil {
t.Errorf("Machine(%s) = %+v, %v; want %v, %v; diff = %v",
tc.in, got, err, tc.want, tc.err, diff)
}
})
}
}
func TestListMachines(t *testing.T) {
testCases := map[string]struct {
want []*Machine
err error
}{
"good": {
// TODO: If this relies on order we should ensure that it will be
// consistent for the tests.
want: []*Machine{testUbuntuMachine, testGoVirtualboxMachine},
err: nil,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
m := newTestManager()
got, err := m.ListMachines(context.Background())
if diff := deep.Equal(got, tc.want); !errors.Is(err, tc.err) || diff != nil {
t.Errorf("ListMachines() = %v, %v; want %v, %v; diff = %v",
got, err, tc.want, tc.err, diff)
}
})
}
}
func TestModifyMachine(t *testing.T) {
// TODO: Figure out how we can do this test, it has pretty extensive flag list
// so having a file in the testdata with such a long name doesn't make
// sense.
}