-
Notifications
You must be signed in to change notification settings - Fork 13
/
mock_modules.go
194 lines (160 loc) · 4.99 KB
/
mock_modules.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package data_plane
import (
"net"
kglb_pb "dropbox/proto/kglb"
)
// set of fake modules with no functionality inside, but to simplify
// overriding required functions.
// Bgp
type MockBgpModule struct {
InitFunc func(asn uint32) error
AdvertiseFunc func(bgpConfig *kglb_pb.BgpRouteAttributes) error
WithdrawFunc func(bgpConfig *kglb_pb.BgpRouteAttributes) error
ListPathsFunc func() ([]*kglb_pb.BgpRouteAttributes, error)
IsSessionEstablishedFunc func() (bool, error)
}
func (m *MockBgpModule) Init(asn uint32) error {
if m.AdvertiseFunc == nil {
return notImplErr
}
return m.InitFunc(asn)
}
func (m *MockBgpModule) Advertise(bgpConfig *kglb_pb.BgpRouteAttributes) error {
if m.AdvertiseFunc == nil {
return notImplErr
}
return m.AdvertiseFunc(bgpConfig)
}
func (m *MockBgpModule) Withdraw(bgpConfig *kglb_pb.BgpRouteAttributes) error {
if m.WithdrawFunc == nil {
return notImplErr
}
return m.WithdrawFunc(bgpConfig)
}
func (m *MockBgpModule) ListPaths() ([]*kglb_pb.BgpRouteAttributes, error) {
if m.WithdrawFunc == nil {
return nil, notImplErr
}
return m.ListPathsFunc()
}
func (m *MockBgpModule) IsSessionEstablished() (bool, error) {
if m.IsSessionEstablishedFunc == nil {
return false, notImplErr
}
return m.IsSessionEstablishedFunc()
}
// AddressTableModule.
type MockAddressTableModule struct {
AddFunc func(addr net.IP, iface string) error
DeleteFunc func(addr net.IP, iface string) error
IsExistsFunc func(addr net.IP, iface string) (bool, error)
ListFunc func(iface string) ([]net.IP, error)
}
func (m *MockAddressTableModule) Add(addr net.IP, iface string) error {
if m.AddFunc == nil {
return notImplErr
}
return m.AddFunc(addr, iface)
}
func (m *MockAddressTableModule) Delete(addr net.IP, iface string) error {
if m.DeleteFunc == nil {
return notImplErr
}
return m.DeleteFunc(addr, iface)
}
func (m *MockAddressTableModule) IsExists(addr net.IP, iface string) (bool, error) {
if m.IsExistsFunc == nil {
return false, notImplErr
}
return m.IsExistsFunc(addr, iface)
}
func (m *MockAddressTableModule) List(iface string) ([]net.IP, error) {
if m.ListFunc == nil {
return nil, notImplErr
}
return m.ListFunc(iface)
}
type MockIpvsModule struct {
AddServiceFunc func(service *kglb_pb.IpvsService) error
// Delete ipvs service.
DeleteServiceFunc func(service *kglb_pb.IpvsService) error
// Get list of existent ipvs Services.
ListServicesFunc func() ([]*kglb_pb.IpvsService, []*kglb_pb.Stats, error)
// Add destination to the specific ipvs service.
AddRealServerFunc func(service *kglb_pb.IpvsService, dst *kglb_pb.UpstreamState) error
// Delete destination from specific ipvs service.
DeleteRealServerFunc func(service *kglb_pb.IpvsService, dst *kglb_pb.UpstreamState) error
// Update destination for specific ipvs service.
UpdateRealServerFunc func(service *kglb_pb.IpvsService, dst *kglb_pb.UpstreamState) error
// Get list of destinations of specific ipvs service
GetRealServersFunc func(
service *kglb_pb.IpvsService) ([]*kglb_pb.UpstreamState, []*kglb_pb.Stats, error)
}
func (m *MockIpvsModule) AddService(service *kglb_pb.IpvsService) error {
if m.AddServiceFunc != nil {
return m.AddServiceFunc(service)
}
return notImplErr
}
// Delete ipvs service.
func (m *MockIpvsModule) DeleteService(service *kglb_pb.IpvsService) error {
if m.DeleteServiceFunc != nil {
return m.DeleteServiceFunc(service)
}
return notImplErr
}
// Get list of existent ipvs Services.
func (m *MockIpvsModule) ListServices() ([]*kglb_pb.IpvsService, []*kglb_pb.Stats, error) {
if m.ListServicesFunc != nil {
return m.ListServicesFunc()
}
return nil, nil, notImplErr
}
// Add destination to the specific ipvs service.
func (m *MockIpvsModule) AddRealServers(
service *kglb_pb.IpvsService, dsts []*kglb_pb.UpstreamState) error {
if m.AddRealServerFunc != nil {
for _, dst := range dsts {
if err := m.AddRealServerFunc(service, dst); err != nil {
return err
}
}
return nil
}
return notImplErr
}
// Delete destination from specific ipvs service.
func (m *MockIpvsModule) DeleteRealServers(
service *kglb_pb.IpvsService, dsts []*kglb_pb.UpstreamState) error {
if m.DeleteRealServerFunc != nil {
for _, dst := range dsts {
if err := m.DeleteRealServerFunc(service, dst); err != nil {
return err
}
}
return nil
}
return notImplErr
}
// Update destination for specific ipvs service.
func (m *MockIpvsModule) UpdateRealServers(
service *kglb_pb.IpvsService, dsts []*kglb_pb.UpstreamState) error {
if m.UpdateRealServerFunc != nil {
for _, dst := range dsts {
if err := m.UpdateRealServerFunc(service, dst); err != nil {
return err
}
}
return nil
}
return notImplErr
}
// Get list of destinations of specific ipvs service
func (m *MockIpvsModule) GetRealServers(
service *kglb_pb.IpvsService) ([]*kglb_pb.UpstreamState, []*kglb_pb.Stats, error) {
if m.GetRealServersFunc != nil {
return m.GetRealServersFunc(service)
}
return nil, nil, notImplErr
}
var _ IpvsModule = &MockIpvsModule{}