2022-09-05 09:06:35 +02:00
|
|
|
package routemanager
|
|
|
|
|
|
|
|
import (
|
2023-05-31 18:25:24 +02:00
|
|
|
"context"
|
2022-09-05 09:06:35 +02:00
|
|
|
"fmt"
|
2023-05-31 18:25:24 +02:00
|
|
|
|
2023-12-08 10:48:21 +01:00
|
|
|
firewall "github.com/netbirdio/netbird/client/firewall/manager"
|
2023-11-02 19:04:33 +01:00
|
|
|
"github.com/netbirdio/netbird/client/internal/listener"
|
2024-04-23 14:42:53 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routeselector"
|
2023-05-31 18:25:24 +02:00
|
|
|
"github.com/netbirdio/netbird/iface"
|
2022-09-05 09:06:35 +02:00
|
|
|
"github.com/netbirdio/netbird/route"
|
2024-06-17 09:47:17 +02:00
|
|
|
"github.com/netbirdio/netbird/util/net"
|
2022-09-05 09:06:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// MockManager is the mock instance of a route manager
|
|
|
|
type MockManager struct {
|
2024-05-06 14:47:49 +02:00
|
|
|
UpdateRoutesFunc func(updateSerial uint64, newRoutes []*route.Route) (map[route.ID]*route.Route, route.HAMap, error)
|
|
|
|
TriggerSelectionFunc func(haMap route.HAMap)
|
2024-04-23 14:42:53 +02:00
|
|
|
GetRouteSelectorFunc func() *routeselector.RouteSelector
|
|
|
|
StopFunc func()
|
2022-09-05 09:06:35 +02:00
|
|
|
}
|
|
|
|
|
2024-06-17 09:47:17 +02:00
|
|
|
func (m *MockManager) Init() (net.AddHookFunc, net.RemoveHookFunc, error) {
|
2024-04-08 18:56:52 +02:00
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
2023-06-12 14:43:55 +02:00
|
|
|
// InitialRouteRange mock implementation of InitialRouteRange from Manager interface
|
|
|
|
func (m *MockManager) InitialRouteRange() []string {
|
2023-05-31 18:25:24 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:06:35 +02:00
|
|
|
// UpdateRoutes mock implementation of UpdateRoutes from Manager interface
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *MockManager) UpdateRoutes(updateSerial uint64, newRoutes []*route.Route) (map[route.ID]*route.Route, route.HAMap, error) {
|
2022-09-05 09:06:35 +02:00
|
|
|
if m.UpdateRoutesFunc != nil {
|
|
|
|
return m.UpdateRoutesFunc(updateSerial, newRoutes)
|
|
|
|
}
|
2024-04-23 14:42:53 +02:00
|
|
|
return nil, nil, fmt.Errorf("method UpdateRoutes is not implemented")
|
|
|
|
}
|
|
|
|
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *MockManager) TriggerSelection(networks route.HAMap) {
|
2024-04-23 14:42:53 +02:00
|
|
|
if m.TriggerSelectionFunc != nil {
|
|
|
|
m.TriggerSelectionFunc(networks)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRouteSelector mock implementation of GetRouteSelector from Manager interface
|
|
|
|
func (m *MockManager) GetRouteSelector() *routeselector.RouteSelector {
|
|
|
|
if m.GetRouteSelectorFunc != nil {
|
|
|
|
return m.GetRouteSelectorFunc()
|
|
|
|
}
|
|
|
|
return nil
|
2022-09-05 09:06:35 +02:00
|
|
|
}
|
|
|
|
|
2023-05-31 18:25:24 +02:00
|
|
|
// Start mock implementation of Start from Manager interface
|
|
|
|
func (m *MockManager) Start(ctx context.Context, iface *iface.WGIface) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRouteChangeListener mock implementation of SetRouteChangeListener from Manager interface
|
2023-11-02 19:04:33 +01:00
|
|
|
func (m *MockManager) SetRouteChangeListener(listener listener.NetworkChangeListener) {
|
2023-05-31 18:25:24 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-12-08 10:48:21 +01:00
|
|
|
func (m *MockManager) EnableServerRouter(firewall firewall.Manager) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:06:35 +02:00
|
|
|
// Stop mock implementation of Stop from Manager interface
|
|
|
|
func (m *MockManager) Stop() {
|
|
|
|
if m.StopFunc != nil {
|
|
|
|
m.StopFunc()
|
|
|
|
}
|
|
|
|
}
|