-
Notifications
You must be signed in to change notification settings - Fork 5
/
serverappliances_test.go
79 lines (68 loc) · 2 KB
/
serverappliances_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
package oneandone
import (
"fmt"
"strings"
"testing"
)
// /server_appliances tests
func TestListServerAppliances(t *testing.T) {
fmt.Println("Listing all server appliances...")
res, err := api.ListServerAppliances()
if err != nil {
t.Errorf("ListServerAppliances failed. Error: " + err.Error())
}
if len(res) == 0 {
t.Errorf("No server appliance found.")
}
res, err = api.ListServerAppliances(1, 7, "name", "", "id,name,os_family")
if err != nil {
t.Errorf("ListServerAppliances with parameter options failed. Error: " + err.Error())
}
if len(res) == 0 {
t.Errorf("No server appliance found.")
}
if len(res) != 7 {
t.Errorf("Wrong number of objects per page.")
}
for index := 0; index < len(res); index += 1 {
if res[index].Id == "" {
t.Errorf("Filtering a list of server appliances failed.")
}
if res[index].Name == "" {
t.Errorf("Filtering a list of server appliances failed.")
}
if res[index].Type != "" {
t.Errorf("Filtering parameters failed.")
}
if index < len(res)-1 {
if res[index].Name > res[index+1].Name {
t.Errorf("Sorting a list of server appliances failed.")
}
}
}
// Test for error response
res, err = api.ListServerAppliances(nil, nil, nil, nil, nil)
if res != nil || err == nil {
t.Errorf("ListServerAppliances failed to handle incorrect argument type.")
}
res, err = api.ListServerAppliances(0, 0, "", "linux", "")
if err != nil {
t.Errorf("ListServerAppliances with parameter options failed. Error: " + err.Error())
}
for _, sa := range res {
if !strings.Contains(strings.ToLower(sa.OsFamily), "linux") {
t.Errorf("Search parameter failed.")
}
}
}
func TestGetServerAppliance(t *testing.T) {
saps, _ := api.ListServerAppliances(1, 1, "", "", "")
fmt.Printf("Getting server appliance '%s'...\n", saps[0].Name)
sa, err := api.GetServerAppliance(saps[0].Id)
if sa == nil || err != nil {
t.Errorf("GetServerAppliance failed. Error: " + err.Error())
}
if sa.Id != saps[0].Id {
t.Errorf("Wrong ID of the server appliance.")
}
}