forked from vultr/govultr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso_test.go
151 lines (125 loc) · 3.92 KB
/
iso_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
145
146
147
148
149
150
151
package govultr
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestIsoServiceHandler_Create(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/iso", func(writer http.ResponseWriter, request *http.Request) {
response := `{"iso":{"id":"9931","date_created":"2020-07-0917:15:27","filename":"CentOS-8.1.1911-x86_64-dvd1.iso","status":"pending"}}`
fmt.Fprint(writer, response)
})
isoReq := &ISOReq{URL: "http://centos.com/CentOS-8.1.1911-x86_64-dvd1.iso"}
iso, _, err := client.ISO.Create(ctx, isoReq)
if err != nil {
t.Errorf("Iso.Create returned %+v, expected %+v", err, nil)
}
expected := &ISO{
ID: "9931",
DateCreated: "2020-07-0917:15:27",
FileName: "CentOS-8.1.1911-x86_64-dvd1.iso",
Size: 0,
MD5Sum: "",
SHA512Sum: "",
Status: "pending",
}
if !reflect.DeepEqual(iso, expected) {
t.Errorf("Iso.Create returned %+v, expected %+v", iso, expected)
}
}
func TestIsoServiceHandler_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/iso/9931", func(writer http.ResponseWriter, request *http.Request) {
response := `{"iso":{"id":"9931","date_created":"2020-07-0917:15:27","filename":"CentOS-8.1.1911-x86_64-dvd1.iso","status":"pending"}}`
fmt.Fprint(writer, response)
})
iso, _, err := client.ISO.Get(ctx, "9931")
if err != nil {
t.Errorf("Iso.Get returned %+v, expected %+v", err, nil)
}
expected := &ISO{
ID: "9931",
DateCreated: "2020-07-0917:15:27",
FileName: "CentOS-8.1.1911-x86_64-dvd1.iso",
Size: 0,
MD5Sum: "",
SHA512Sum: "",
Status: "pending",
}
if !reflect.DeepEqual(iso, expected) {
t.Errorf("Iso.Get returned %+v, expected %+v", iso, expected)
}
}
func TestIsoServiceHandler_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/iso/24", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})
err := client.ISO.Delete(ctx, "24")
if err != nil {
t.Errorf("Iso.Delete returned %+v, expected %+v", err, nil)
}
}
func TestIsoServiceHandler_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/iso", func(writer http.ResponseWriter, request *http.Request) {
response := `{"isos":[{"id":"9931","date_created":"2020-07-0917:15:27","filename":"CentOS-8.1.1911-x86_64-dvd1.iso","status":"pending"}],"meta":{"total":8,"links":{"next":"","prev":""}}}`
fmt.Fprint(writer, response)
})
iso, meta, _, err := client.ISO.List(ctx, nil)
if err != nil {
t.Errorf("Iso.List returned %+v, expected %+v", err, nil)
}
expectedIso := []ISO{
{
ID: "9931",
DateCreated: "2020-07-0917:15:27",
FileName: "CentOS-8.1.1911-x86_64-dvd1.iso",
Size: 0,
MD5Sum: "",
SHA512Sum: "",
Status: "pending",
},
}
expectedMeta := &Meta{
Total: 8,
Links: &Links{},
}
if !reflect.DeepEqual(iso, expectedIso) {
t.Errorf("Iso.List iso returned %+v, expected %+v", iso, expectedIso)
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("Iso.List returned %+v, expected %+v", meta, expectedMeta)
}
}
func TestIsoServiceHandler_ListPublic(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/iso-public", func(writer http.ResponseWriter, request *http.Request) {
response := `{"public_isos": [{"id": "204515","name": "CentOS 7","description": "7 x86_64 Minimal"}],"meta":{"total":8,"links":{"next":"","prev":""}}}`
fmt.Fprint(writer, response)
})
iso, meta, _, err := client.ISO.ListPublic(ctx, nil)
if err != nil {
t.Errorf("Iso.ListPublic returned %+v, expected %+v", err, nil)
}
expectedIso := []PublicISO{
{ID: "204515", Name: "CentOS 7", Description: "7 x86_64 Minimal"},
}
expectedMeta := &Meta{
Total: 8,
Links: &Links{},
}
if !reflect.DeepEqual(iso, expectedIso) {
t.Errorf("Iso.ListPublic iso returned %+v, expected %+v", iso, expectedIso)
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("Iso.ListPublic meta returned %+v, expected %+v", meta, expectedMeta)
}
}