-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdisk_test.go
97 lines (79 loc) · 1.83 KB
/
disk_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
94
95
96
97
package virtualbox
import (
"io/ioutil"
"os"
"os/user"
"path/filepath"
"reflect"
"testing"
)
func TestVbox_CreateDelete(t *testing.T) {
dirName, err := ioutil.TempDir("", "vbm")
if err != nil {
t.Errorf("CreateDisk failed %v", err)
}
defer os.RemoveAll(dirName)
expected := Disk{
Path: filepath.Join(dirName, "disk1.vdi"),
Format: VDI,
SizeMB: 10,
}
var vb VBox
err = vb.CreateDisk(&expected)
if err != nil {
t.Errorf("CreateDisk failed %v", err)
}
actual, err := vb.DiskInfo(&expected)
if err != nil {
t.Fatalf("DiksInfo failed with %v", err)
}
if actual.UUID == "" {
t.Fatalf("Disk was not created?")
}
err = vb.DeleteDisk(actual.UUID)
if err != nil {
t.Fatalf("error deleting disk %v", err)
}
actual, err = vb.DiskInfo(&expected)
if err == nil {
t.Fatalf("Expected error, but gone none")
}
if !IsDiskNotFound(err) {
t.Fatalf("Expected DiskNotFoundError error, but gone %v", err)
}
}
func TestShowMediumOutputRegex(t *testing.T) {
var sampleDiskOut = `
UUID: 0e3f0c1b-f523-4a50-b1a8-d1e8c9a508b4
Parent UUID: base
State: created
Type: normal (base)
Storage format: VDI
Format variant: dynamic default
Capacity: 1000 MBytes
Size on disk: 2 MBytes
Encryption: disabled
`
user, _ := user.Current()
expected := Disk{
Path: user.HomeDir + "/.vbm/Vbox/myvm1/disk1.vdi",
Format: VDI,
UUID: "0e3f0c1b-f523-4a50-b1a8-d1e8c9a508b4",
}
//Vbox.CreateDisk(disk1.Path, )
var disk = Disk{}
_ = parseKeyValues(sampleDiskOut, reColonLine, func(key, val string) error {
switch key {
case "UUID":
disk.UUID = val
case "Location":
disk.Path = val
case "Storage format":
disk.Format = DiskFormat(val)
}
return nil
})
if !reflect.DeepEqual(expected, disk) {
t.Errorf("Did not parse showmediuminfo out to disk as expected. Got %+v", disk)
}
}