This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
bgp_neighbors_test.go
76 lines (61 loc) · 1.56 KB
/
bgp_neighbors_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
package packngo
import (
"log"
"testing"
)
func createBGPDevice(t *testing.T, c *Client, projectID string) *Device {
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)
}
d = waitDeviceActive(t, c, d.ID)
aTrue := true
_, _, err = c.BGPSessions.Create(d.ID,
CreateBGPSessionRequest{
AddressFamily: "ipv4",
DefaultRoute: &aTrue})
if err != nil {
t.Fatal(err)
}
return d
}
func TestAccBGPNeighbors(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)
}
d := createBGPDevice(t, c, projectID)
defer deleteDevice(t, c, d.ID, false)
bgpNeighbors, _, err := c.Devices.ListBGPNeighbors(d.ID, nil)
if err != nil {
t.Fatal(err)
}
log.Printf("Testdevice BGP neighbors: \n %+v", bgpNeighbors)
if len(bgpNeighbors) < 1 {
t.Fatal("Device with BGP session should have at least one listed BGP neighbor - itself")
}
n0 := bgpNeighbors[0]
if len(n0.RoutesIn) < 1 {
t.Fatal("Device with BGP session should have at least one route in")
}
if len(n0.RoutesOut) < 1 {
t.Fatal("Device with BGP session should have at least one route out")
}
}