forked from equinixmetal-archive/packngo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgp_sessions_test.go
125 lines (104 loc) · 2.4 KB
/
bgp_sessions_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
package packngo
import (
"testing"
)
func TestAccBGPSession(t *testing.T) {
skipUnlessAcceptanceTestsAllowed(t)
c, projectID, teardown := setupWithProject(t)
defer teardown()
configRequest := CreateBGPConfigRequest{
DeploymentType: "local",
Asn: 65000,
Md5: "c3RhY2twb2ludDIwMTgK",
}
_, err := c.BGPConfig.Create(projectID, configRequest)
if err != nil {
t.Fatal(err)
}
hn := randString8()
cr := DeviceCreateRequest{
Hostname: hn,
Facility: []string{testFacility()},
Plan: testPlan(),
ProjectID: projectID,
BillingCycle: "hourly",
OS: testOS,
}
d, _, err := c.Devices.Create(&cr)
if err != nil {
t.Fatal(err)
}
defer deleteDevice(t, c, d.ID, false)
d = waitDeviceActive(t, c, d.ID)
aTrue := true
bgpSession, _, err := c.BGPSessions.Create(d.ID,
CreateBGPSessionRequest{
AddressFamily: "ipv4",
DefaultRoute: &aTrue})
if err != nil {
t.Fatal(err)
}
sessionID := bgpSession.ID
sessions, _, err := c.Devices.ListBGPSessions(d.ID, nil)
if err != nil {
t.Fatal(err)
}
var check *BGPSession
for _, s := range sessions {
if s.ID == sessionID {
check = &s
break
}
}
if check == nil {
t.Fatal("BGP Session not returned.")
}
if !*(check.DefaultRoute) {
t.Fatal("BGP Session Default Route should have been set.")
}
cs, _, err := c.BGPConfig.Get(projectID,
&GetOptions{Includes: []string{"sessions"}})
if err != nil {
t.Fatal(err)
}
if len(cs.Sessions) != 1 {
t.Fatal("only one Session should be listed in project BGP conf")
}
if cs.Sessions[0].ID != sessionID {
t.Fatal("BGP Session ID mismatch")
}
updatedSession, _, err := c.BGPSessions.Update(bgpSession.ID, UpdateBGPSessionRequest{DefaultRoute: false})
if err != nil {
t.Fatal(err)
}
if updatedSession.ID != sessionID {
t.Fatal("BGP Session mismatch after update")
}
sessions, _, err = c.Projects.ListBGPSessions(projectID, nil)
if err != nil {
t.Fatal(err)
}
for _, s := range sessions {
if s.ID == sessionID {
check = &s
break
}
}
if check == nil {
t.Fatal("BGP Session not returned.")
}
if *check.DefaultRoute {
t.Fatal("default_route should be false after update")
}
_, err = c.BGPSessions.Delete(sessionID)
if err != nil {
t.Fatal(err)
}
session, _, err := c.BGPSessions.Get(sessionID, nil)
if session != nil {
t.Fatal("Session not deleted")
}
if err == nil {
t.Fatal("Session not deleted")
}
}