-
Notifications
You must be signed in to change notification settings - Fork 56
/
vpc_test.go
154 lines (126 loc) · 3.37 KB
/
vpc_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
152
153
154
package govultr
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestVPCServiceHandler_Create(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/vpcs", func(writer http.ResponseWriter, request *http.Request) {
response := `
{
"vpc": {
"id": "net539626f0798d7",
"date_created": "2017-08-25 12:23:45",
"region": "ewr",
"description": "test1",
"v4_subnet": "10.99.0.0",
"v4_subnet_mask": 24
}
}
`
fmt.Fprint(writer, response)
})
options := &VPCReq{
Region: "ewr",
Description: "test1",
}
net, _, err := client.VPC.Create(ctx, options)
if err != nil {
t.Errorf("VPC.Create returned %+v, expected %+v", err, nil)
}
expected := &VPC{
ID: "net539626f0798d7",
Region: "ewr",
Description: "test1",
V4Subnet: "10.99.0.0",
V4SubnetMask: 24,
DateCreated: "2017-08-25 12:23:45",
}
if !reflect.DeepEqual(net, expected) {
t.Errorf("VPC.Create returned %+v, expected %+v", net, expected)
}
}
func TestVPCServiceHandler_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/vpcs/net539626f0798d7", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})
err := client.VPC.Delete(ctx, "net539626f0798d7")
if err != nil {
t.Errorf("VPC.Delete returned %+v, expected %+v", err, nil)
}
}
func TestVPCServiceHandler_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/vpcs", func(writer http.ResponseWriter, request *http.Request) {
response := `
{
"vpcs": [{
"id": "net539626f0798d7",
"date_created": "2017-08-25 12:23:45",
"region": "ewr",
"description": "test1",
"v4_subnet": "10.99.0.0",
"v4_subnet_mask": 24
}]
}
`
fmt.Fprint(writer, response)
})
vpcs, _, _, err := client.VPC.List(ctx, nil)
if err != nil {
t.Errorf("VPC.List returned error: %v", err)
}
expected := []VPC{
{
ID: "net539626f0798d7",
Region: "ewr",
Description: "test1",
V4Subnet: "10.99.0.0",
V4SubnetMask: 24,
DateCreated: "2017-08-25 12:23:45",
},
}
if !reflect.DeepEqual(vpcs, expected) {
t.Errorf("VPC.List returned %+v, expected %+v", vpcs, expected)
}
}
func TestVPCServiceHandler_Update(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/vpcs/net539626f0798d7", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})
err := client.VPC.Update(ctx, "net539626f0798d7", "update")
if err != nil {
t.Errorf("VPC.Update returned %+v, expected %+v", err, nil)
}
}
func TestVPCServiceHandler_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/vpcs/net539626f0798d7", func(writer http.ResponseWriter, request *http.Request) {
req := `{"vpc": {"id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60","date_created": "2020-10-10T01:56:20+00:00","region": "ewr","description": "sample desc","v4_subnet": "10.99.0.0","v4_subnet_mask": 24}}`
fmt.Fprint(writer, req)
})
vpc, _, err := client.VPC.Get(ctx, "net539626f0798d7")
if err != nil {
t.Errorf("VPC.Get returned %+v, expected %+v", err, nil)
}
expected := &VPC{
ID: "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
Region: "ewr",
Description: "sample desc",
V4Subnet: "10.99.0.0",
V4SubnetMask: 24,
DateCreated: "2020-10-10T01:56:20+00:00",
}
if !reflect.DeepEqual(vpc, expected) {
t.Errorf("VPC.Get returned %+v, expected %+v", vpc, expected)
}
}