-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf_test.go
134 lines (122 loc) · 3.3 KB
/
conf_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
package main
import "testing"
var TestsGetVMbyName = []struct {
input string
expectd string
}{
{"gh-test", "gh-test"},
{"gh-test1", "gh-test1"},
{"gh-test2", "gh-test2"},
{"gh-test3", "gh-test3"},
{"gh-test4", "gh-test4"},
{"adawdawdwa", ""},
{"≠²³≠≠≠gh-test4", ""},
{"", ""},
{"asdasdawda121302803912830123", ""},
{"≠²³≠²³≠¢³¢€¢€§€·§½", ""},
}
func TestGetVMbyName(t *testing.T) {
writeExampleConfig()
confLoad()
for _, tt := range TestsGetVMbyName {
actual := config.GetVMbyName(&tt.input)
if actual != nil && actual.Name != tt.expectd {
t.Errorf("GetVMByDomain(%s): expected %v, actual %v", tt.input, tt.expectd, actual)
}
}
}
var TestsGetVMbyDomain = []struct {
input string
expectd string
}{
{"tests struct embedded in main cluster.conf", "gh-test"},
{"/mnt/cephvm/libvirt/domains/gh-test1.xml", "gh-test1"},
{"/mnt/cephvm/libvirt/domains/gh-test2.xml", "gh-test2"},
{"/mnt/cephvm/libvirt/domains/gh-test3.xml", "gh-test3"},
{"/mnt/cephvm/libvirt/domains/gh-test4.xml", "gh-test4"},
{"adawdawdwa", ""},
{"≠²³≠≠≠gh-test4", ""},
{"", ""},
{"asdasdawda121302803912830123", ""},
{"≠²³≠²³≠¢³¢€¢€§€·§½", ""},
}
func TestGetVMbyDomain(t *testing.T) {
writeExampleConfig()
confLoad()
for _, tt := range TestsGetVMbyDomain {
actual := config.GetVMbyDomain(&tt.input)
if (actual != nil && actual.Name != tt.expectd) || (actual == nil && tt.expectd != "") {
t.Errorf("GetVMByDomain(%s): expected %v, actual %v", tt.input, tt.expectd, actual)
}
}
}
var TestsGetNodebyHostname = []struct {
input string
expectd string
}{
{"r210II-1", "r210II-1"},
{"r210II-2", "r210II-2"},
{"r210II-3", "r210II-3"},
{"notExisting node 1", ""},
{"notExisting node 2", ""},
{"notExisting node 3", ""},
{"notExisting node 4", ""},
{"notExisting node 5", ""},
}
func TestGetNodebyHostname(t *testing.T) {
writeExampleConfig()
confLoad()
for _, tt := range TestsGetNodebyHostname {
actual := config.GetNodebyHostname(&tt.input)
if actual != nil && actual.Hostname != tt.expectd {
t.Errorf("GetNodebyHostname(%s): expected %v, actual %v", tt.input, tt.expectd, actual)
}
}
}
var TestsCheckIfNodeExists = []struct {
input string
expectd bool
}{
{"r210II-1", true},
{"r210II-2", true},
{"r320-1", true},
{"notExisting node 1", false},
{"notExisting node 2", false},
{"notExisting node 3", false},
{"notExisting node 4", false},
{"notExisting node 5", false},
}
func TestCheckIfNodeExists(t *testing.T) {
writeExampleConfig()
confLoad()
for _, tt := range TestsCheckIfNodeExists {
actual := config.CheckIfNodeExists(&tt.input)
if actual != tt.expectd {
t.Errorf("CheckIfNodeExists(%s): expected %v, actual %v", tt.input, tt.expectd, actual)
}
}
}
//var TestsFUNC = []struct {
// input string
// expectd bool
//}{
// {"r210II-1", true},
// {"r210II-2", true},
// {"r210II-3", true},
// {"notExisting node 1", false},
// {"notExisting node 2", false},
// {"notExisting node 3", false},
// {"notExisting node 4", false},
// {"notExisting node 5", false},
//}
//
//func TestFUNC(t *testing.T) {
// writeExampleConfig()
// confLoad()
// for _, tt := range TestsFUNC {
// actual := config.FUNC(&tt.input)
// if actual.Hostname != tt.expectd {
// t.Errorf("FUNC(%s): expected %v, actual %v", tt.input, tt.expectd, actual)
// }
// }
//}