-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute_test.go
More file actions
130 lines (121 loc) · 3.1 KB
/
Copy pathroute_test.go
File metadata and controls
130 lines (121 loc) · 3.1 KB
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
package fortimgr
import (
"context"
"testing"
)
func TestListStaticRoutes(t *testing.T) {
t.Run("not logged in", func(t *testing.T) {
c, _ := NewClient("https://example.com", WithCredentials("u", "p"))
_, err := c.ListStaticRoutes(context.Background(), "fw-01", "root")
if err != ErrNotLoggedIn {
t.Errorf("err = %v, want ErrNotLoggedIn", err)
}
})
t.Run("success", func(t *testing.T) {
client := newTestClient(t, map[string]string{
"/pm/config/device/fw-01/vdom/root/router/static": `[
{
"seq-num": 1,
"dst": ["0.0.0.0", "0.0.0.0"],
"gateway": "10.0.0.1",
"device": "wan1",
"distance": 10,
"priority": 0,
"status": 1,
"comment": "Default route"
},
{
"seq-num": 2,
"dst": ["192.168.10.0", "255.255.255.0"],
"gateway": "10.0.1.1",
"device": "port2",
"distance": 20,
"priority": 5,
"status": 0,
"comment": ""
}
]`,
})
routes, err := client.ListStaticRoutes(context.Background(), "fw-01", "root")
if err != nil {
t.Fatal(err)
}
if len(routes) != 2 {
t.Fatalf("len = %d, want 2", len(routes))
}
r := routes[0]
if r.SeqNum != 1 {
t.Errorf("SeqNum = %d", r.SeqNum)
}
if r.Dst != "0.0.0.0/0" {
t.Errorf("Dst = %q, want \"0.0.0.0/0\"", r.Dst)
}
if r.Gateway != "10.0.0.1" {
t.Errorf("Gateway = %q", r.Gateway)
}
if r.Device != "wan1" {
t.Errorf("Device = %q", r.Device)
}
if r.Distance != 10 {
t.Errorf("Distance = %d", r.Distance)
}
if r.Status != "enable" {
t.Errorf("Status = %q, want \"enable\"", r.Status)
}
if r.Comment != "Default route" {
t.Errorf("Comment = %q", r.Comment)
}
r2 := routes[1]
if r2.Dst != "192.168.10.0/24" {
t.Errorf("Dst = %q, want \"192.168.10.0/24\"", r2.Dst)
}
if r2.Status != "disable" {
t.Errorf("Status = %q, want \"disable\"", r2.Status)
}
if r2.Priority != 5 {
t.Errorf("Priority = %d, want 5", r2.Priority)
}
})
}
func TestListStaticRoutes6(t *testing.T) {
t.Run("not logged in", func(t *testing.T) {
c, _ := NewClient("https://example.com", WithCredentials("u", "p"))
_, err := c.ListStaticRoutes6(context.Background(), "fw-01", "root")
if err != ErrNotLoggedIn {
t.Errorf("err = %v, want ErrNotLoggedIn", err)
}
})
t.Run("success", func(t *testing.T) {
client := newTestClient(t, map[string]string{
"/pm/config/device/fw-01/vdom/root/router/static6": `[
{
"seq-num": 1,
"dst": "::/0",
"gateway": "2001:db8::1",
"device": "wan1",
"distance": 10,
"priority": 0,
"status": 1,
"comment": "Default IPv6 route"
}
]`,
})
routes, err := client.ListStaticRoutes6(context.Background(), "fw-01", "root")
if err != nil {
t.Fatal(err)
}
if len(routes) != 1 {
t.Fatalf("len = %d, want 1", len(routes))
}
r := routes[0]
if r.SeqNum != 1 || r.Dst != "::/0" || r.Gateway != "2001:db8::1" || r.Device != "wan1" {
t.Errorf("route = %+v", r)
}
if r.Distance != 10 || r.Priority != 0 || r.Status != "enable" {
t.Errorf("route status fields = %+v", r)
}
if r.Comment != "Default IPv6 route" {
t.Errorf("Comment = %q", r.Comment)
}
})
}