forked from equinixmetal-archive/packngo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip_test.go
94 lines (80 loc) · 2.06 KB
/
ip_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
package packngo
import (
"path"
"testing"
)
func TestAccIPReservation(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
quantityToMask := map[int]int{
1: 32, 2: 31, 4: 30, 8: 29, 16: 28,
}
testFac := testFacility()
quantity := 2
ipList, _, err := c.ProjectIPs.List(projectID)
if err != nil {
t.Fatal(err)
}
if len(ipList) != 0 {
t.Fatalf("There should be no reservations a new project, existing list: %s", ipList)
}
req := IPReservationRequest{
Type: "public_ipv4",
Quantity: quantity,
Comments: "packngo test",
Facility: testFac,
}
res, _, err := c.ProjectIPs.Request(projectID, &req)
if err != nil {
t.Fatal(err)
}
if res.CIDR != quantityToMask[quantity] {
t.Fatalf(
"CIDR prefix length for requested reservation should be %d, was %d",
quantityToMask[quantity], res.CIDR)
}
if path.Base(res.Project.Href) != projectID {
t.Fatalf("Wrong project linked in reserved block: %s", res.Project.Href)
}
if res.Management {
t.Fatal("Management flag of new reservation block must be False")
}
if res.Facility.Code != testFac {
t.Fatalf(
"Facility of new reservation should be %s, was %s", testFac,
res.Facility.Code)
}
ipList, _, err = c.ProjectIPs.List(projectID)
if len(ipList) != 1 {
t.Fatalf("There should be only one reservation, was: %s", ipList)
}
if err != nil {
t.Fatal(err)
}
sameRes, _, err := c.ProjectIPs.Get(res.ID)
if err != nil {
t.Fatal(err)
}
if sameRes.ID != res.ID {
t.Fatalf("re-requested test reservation should be %s, is %s",
res, sameRes)
}
availableAddresses, _, err := c.ProjectIPs.AvailableAddresses(
res.ID, &AvailableRequest{CIDR: 32})
if err != nil {
t.Fatal(err)
}
if len(availableAddresses) != quantity {
t.Fatalf("New block should have %d available addresses, got %s",
quantity, availableAddresses)
}
_, err = c.ProjectIPs.Remove(res.ID)
if err != nil {
t.Fatal(err)
}
_, _, err = c.ProjectIPs.Get(res.ID)
if err == nil {
t.Fatalf("Reservation %s should be deleted at this point", res)
}
}