-
Notifications
You must be signed in to change notification settings - Fork 468
/
Copy pathutils_domain_def_test.go
144 lines (117 loc) · 3.11 KB
/
utils_domain_def_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package libvirt
import (
"reflect"
"testing"
"time"
"github.com/davecgh/go-spew/spew"
)
func init() {
spew.Config.Indent = "\t"
}
func TestSplitKernelCmdLine(t *testing.T) {
e := []map[string]string{
{"foo": "bar"},
{
"foo": "bar",
"key": "val",
"root": "UUID=aa52d618-a2c4-4aad-aeb7-68d9e3a2c91d",
},
{"_": "nosplash rw"},
}
r := splitKernelCmdLine("foo=bar foo=bar key=val root=UUID=aa52d618-a2c4-4aad-aeb7-68d9e3a2c91d nosplash rw")
if !reflect.DeepEqual(r, e) {
t.Fatalf("got='%s' expected='%s'", spew.Sdump(r), spew.Sdump(e))
}
}
func TestSplitKernelEmptyCmdLine(t *testing.T) {
var e []map[string]string
r := splitKernelCmdLine("")
if !reflect.DeepEqual(r, e) {
t.Fatalf("got='%s' expected='%s'", spew.Sdump(r), spew.Sdump(e))
}
}
func TestGetHostArchitecture(t *testing.T) {
skipIfAccDisabled(t)
conn := testAccProvider.Meta().(*Client).libvirt
arch, err := getHostArchitecture(conn)
if err != nil {
t.Errorf("error %v", err)
}
t.Logf("[DEBUG] arch - %s", arch)
if arch == "" {
t.Errorf("arch is blank.")
}
}
func TestGetCanonicalMachineName(t *testing.T) {
skipIfAccDisabled(t)
conn := testAccProvider.Meta().(*Client).libvirt
arch := "x86_64"
virttype := "hvm"
machine := "pc"
caps, err := getHostCapabilities(conn)
if err != nil {
t.Error(err)
}
name, err := getCanonicalMachineName(caps, arch, virttype, machine)
if err != nil {
t.Errorf("Could not get canonical name for %s/%s", arch, machine)
return
}
t.Logf("Canonical name for %s/%s = %s", arch, machine, name)
}
func TestGetOriginalMachineName(t *testing.T) {
skipIfAccDisabled(t)
conn := testAccProvider.Meta().(*Client).libvirt
arch := "x86_64"
virttype := "hvm"
machine := "pc"
caps, err := getHostCapabilities(conn)
if err != nil {
t.Error(err)
}
canonname, err := getCanonicalMachineName(caps, arch, virttype, machine)
if err != nil {
t.Error(err)
}
reversename, err := getOriginalMachineName(caps, arch, virttype, canonname)
if err != nil {
t.Error(err)
}
if reversename != machine {
t.Errorf("Cannot reverse canonical machine lookup")
}
t.Logf("Reverse canonical lookup for %s is %s which matches %s", canonname, reversename, machine)
}
func TestGetMachineTypeForArch(t *testing.T) {
skipIfAccDisabled(t)
conn := testAccProvider.Meta().(*Client).libvirt
caps, err := getHostCapabilities(conn)
if err != nil {
t.Error(err)
}
arch := "x86_64"
targettype := "hvm"
machine := "pc"
m, err := getMachineTypeForArch(caps, arch, targettype)
if err != nil {
t.Error(err)
}
if m != machine {
t.Errorf("Machine found for arch %s, targettype %s is %s expected %s", arch, targettype, m, machine)
}
t.Logf("Machine for arch %s, targettype %s is %s which matches %s", arch, targettype, m, machine)
}
func TestGetHostCapabilties(t *testing.T) {
skipIfAccDisabled(t)
conn := testAccProvider.Meta().(*Client).libvirt
start := time.Now()
caps, err := getHostCapabilities(conn)
if err != nil {
t.Errorf("Can't get host capabilties")
}
if caps.Host.UUID == "" {
t.Errorf("Host has no UUID!")
}
elapsed := time.Since(start)
t.Logf("[DEBUG] Get host capabilities took %s", elapsed)
}