forked from equinixmetal-archive/packngo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetal_gateway_test.go
126 lines (102 loc) · 2.6 KB
/
metal_gateway_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
package packngo
import (
"testing"
)
func TestAccMetalGatewaySubnetSize(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
testDesc := "test_desc_" + randString8()
vcr := VirtualNetworkCreateRequest{
ProjectID: projectID,
Description: testDesc,
Metro: testMetro(),
}
vlan, _, err := c.ProjectVirtualNetworks.Create(&vcr)
if err != nil {
t.Fatal(err)
}
rcr := MetalGatewayCreateRequest{
VirtualNetworkID: vlan.ID,
PrivateIPv4SubnetSize: 8,
}
router, _, err := c.MetalGateways.Create(projectID, &rcr)
if err != nil {
t.Fatal(err)
}
includes := &GetOptions{Includes: []string{"ip_reservation", "virtual_network"}}
router, _, err = c.MetalGateways.Get(router.ID, includes)
if err != nil {
t.Fatal(err)
}
routers, _, err := c.MetalGateways.List(projectID, nil)
if err != nil {
t.Fatal(err)
}
if len(routers) != 1 {
t.Fatalf("There should be exactly one metal gateway in the testing project")
}
_, err = c.MetalGateways.Delete(router.ID)
if err != nil {
t.Fatal(err)
}
_, err = c.ProjectVirtualNetworks.Delete(vlan.ID)
if err != nil {
t.Fatal(err)
}
}
func TestAccMetalGatewayExistingReservation(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
testDesc := "test_desc_" + randString8()
vcr := VirtualNetworkCreateRequest{
ProjectID: projectID,
Description: testDesc,
Metro: testMetro(),
}
vlan, _, err := c.ProjectVirtualNetworks.Create(&vcr)
if err != nil {
t.Fatal(err)
}
metro := testMetro()
ipcr := IPReservationRequest{
Type: PublicIPv4,
Quantity: 8,
Metro: &metro,
FailOnApprovalRequired: true,
}
ipRes, _, err := c.ProjectIPs.Create(projectID, &ipcr)
if err != nil {
t.Fatal(err)
}
rcr := MetalGatewayCreateRequest{
VirtualNetworkID: vlan.ID,
IPReservationID: ipRes.ID,
}
router, _, err := c.MetalGateways.Create(projectID, &rcr)
if err != nil {
t.Fatal(err)
}
includes := &GetOptions{Includes: []string{"ip_reservation", "virtual_network"}}
router, _, err = c.MetalGateways.Get(router.ID, includes)
if err != nil {
t.Fatal(err)
}
routers, _, err := c.MetalGateways.List(projectID, nil)
if err != nil {
t.Fatal(err)
}
if len(routers) != 1 {
t.Fatalf("There should be exactly one metal gateway in the testing project")
}
_, err = c.MetalGateways.Delete(router.ID)
if err != nil {
t.Fatal(err)
}
deleteProjectIP(t, c, ipRes.ID)
_, err = c.ProjectVirtualNetworks.Delete(vlan.ID)
if err != nil {
t.Fatal(err)
}
}