-
Notifications
You must be signed in to change notification settings - Fork 62
/
vbmgt_test.go
59 lines (50 loc) · 1.15 KB
/
vbmgt_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
package virtualbox
import (
"io/ioutil"
"os"
"path"
"testing"
"github.com/golang/mock/gomock"
)
var (
MockCtrl *gomock.Controller
ManageMock *MockCommand
VM string
TestDataFolder string
)
func ReadTestData(file string) string {
out, err := ioutil.ReadFile(path.Join("testdata", file))
if err != nil {
panic("No such file :testdata/" + file)
}
return string(out)
}
func Setup(t *testing.T) {
VM = os.Getenv("TEST_VM")
MockCtrl = gomock.NewController(t)
if len(VM) < 1 {
ManageMock = NewMockCommand(MockCtrl)
manage = ManageMock
t.Logf("Using ManageMock=%v (type=%T)", ManageMock, ManageMock)
} else {
t.Logf("Using real VM='%s'\n", VM)
}
t.Logf("Using Manage='%+v' (type: '%T')", Manage(), Manage())
}
func Teardown() {
defer MockCtrl.Finish()
}
func TestVBMOut(t *testing.T) {
Setup(t)
if ManageMock != nil {
var out = "\"Ubuntu\" {2e16b1fc-aaaa-4a7a-a9a1-e89a8bde7874}\n" +
"\"go-virtualbox\" {def44546-aaaa-4902-8d15-b91c99c80cbc}"
ManageMock.EXPECT().run("list", "vms").Return(out, "", nil)
}
b, _, err := Manage().run("list", "vms")
if err != nil {
t.Fatal(err)
}
t.Logf("%s", b)
Teardown()
}