forked from civo/civogo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstance_size_test.go
116 lines (106 loc) · 3.35 KB
/
instance_size_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
package civogo
import (
"testing"
)
func TestListInstanceSizes(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/sizes": `[
{
"id": "d6b170f2-d2b3-4205-84c4-61898622393d",
"name": "micro",
"nice_name": "Micro",
"cpu_cores": 1,
"ram_mb": 1024,
"disk_gb": 25,
"description": "Micro - 1GB RAM, 1 CPU Core, 25GB SSD Disk",
"selectable": true
}
]
`,
})
defer server.Close()
got, err := client.ListInstanceSizes()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got[0].ID != "d6b170f2-d2b3-4205-84c4-61898622393d" {
t.Errorf("Expected %s, got %s", "d6b170f2-d2b3-4205-84c4-61898622393d", got[0].ID)
}
if got[0].Name != "micro" {
t.Errorf("Expected %s, got %s", "micro", got[0].Name)
}
if got[0].NiceName != "Micro" {
t.Errorf("Expected %s, got %s", "Micro", got[0].NiceName)
}
if got[0].NiceName != "Micro" {
t.Errorf("Expected %s, got %s", "Micro", got[0].NiceName)
}
if !got[0].Selectable {
t.Errorf("Expected first result to be selectable")
}
if got[0].CPUCores != 1 {
t.Errorf("Expected %d, got %d", 1, got[0].CPUCores)
}
if got[0].RAMMegabytes != 1024 {
t.Errorf("Expected %d, got %d", 1024, got[0].RAMMegabytes)
}
if got[0].DiskGigabytes != 25 {
t.Errorf("Expected %d, got %d", 25, got[0].DiskGigabytes)
}
if got[0].Description != "Micro - 1GB RAM, 1 CPU Core, 25GB SSD Disk" {
t.Errorf("Expected %s, got %s", "Micro - 1GB RAM, 1 CPU Core, 25GB SSD Disk", got[0].Description)
}
}
func TestFindInstanceSizes(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/sizes": `[
{
"id": "d6b170f2-d2b3-4205-84c4-61898622393d",
"name": "debian-10",
"nice_name": "Debian 10",
"cpu_cores": 1,
"ram_mb": 1024,
"disk_gb": 25,
"description": "Micro - 1GB RAM, 1 CPU Core, 25GB SSD Disk",
"selectable": true
},
{
"id": "456780f2-d3b3-345-84c4-12345622393d",
"name": "debian-9",
"nice_name": "Debian 9",
"cpu_cores": 1,
"ram_mb": 2024,
"disk_gb": 50,
"description": "Debian - 2GB RAM, 1 CPU Core, 50GB SSD Disk",
"selectable": true
}
]
`,
})
defer server.Close()
got, _ := client.FindInstanceSizes("456780f2")
if got.ID != "456780f2-d3b3-345-84c4-12345622393d" {
t.Errorf("Expected %s, got %s", "456780f2-d3b3-345-84c4-12345622393d", got.ID)
}
got, _ = client.FindInstanceSizes("d6b170")
if got.ID != "d6b170f2-d2b3-4205-84c4-61898622393d" {
t.Errorf("Expected %s, got %s", "d6b170f2-d2b3-4205-84c4-61898622393d", got.ID)
}
got, _ = client.FindInstanceSizes("debian-1")
if got.ID != "d6b170f2-d2b3-4205-84c4-61898622393d" {
t.Errorf("Expected %s, got %s", "d6b170f2-d2b3-4205-84c4-61898622393d", got.ID)
}
got, _ = client.FindInstanceSizes("debian-9")
if got.ID != "456780f2-d3b3-345-84c4-12345622393d" {
t.Errorf("Expected %s, got %s", "456780f2-d3b3-345-84c4-12345622393d", got.ID)
}
_, err := client.FindInstanceSizes("debian")
if err.Error() != "MultipleMatchesError: unable to find debian because there were multiple matches" {
t.Errorf("Expected %s, got %s", "unable to find com because there were multiple matches", err.Error())
}
_, err = client.FindInstanceSizes("missing")
if err.Error() != "ZeroMatchesError: unable to find missing, zero matches" {
t.Errorf("Expected %s, got %s", "unable to find missing, zero matches", err.Error())
}
}