-
Notifications
You must be signed in to change notification settings - Fork 4
/
route_test.go
59 lines (52 loc) · 1.82 KB
/
route_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
package clusterf
import (
"github.com/kylelemons/godebug/pretty"
"github.com/qmsk/clusterf/config"
"github.com/qmsk/clusterf/ipvs"
"net"
"testing"
)
var testIpvsFwdMethodMasq = ipvs.FwdMethod(ipvs.IP_VS_CONN_F_MASQ)
var testIpvsFwdMethodDroute = ipvs.FwdMethod(ipvs.IP_VS_CONN_F_DROUTE)
var testRoutes = Routes{
"test2": Route{
Prefix: &net.IPNet{net.IP{10, 2, 0, 0}, net.IPMask{255, 255, 255, 0}},
Gateway: net.IP{10, 255, 0, 2},
IPVSMethod: &testIpvsFwdMethodMasq,
},
"test1": Route{
Prefix: &net.IPNet{net.IP{10, 1, 0, 0}, net.IPMask{255, 255, 255, 0}},
Gateway: nil,
IPVSMethod: &testIpvsFwdMethodMasq,
},
"internal": Route{
Prefix: &net.IPNet{net.IP{10, 0, 0, 0}, net.IPMask{255, 0, 0, 0}},
},
}
// Test basic route configuration
// Test multiple NewConfig for Routes from multiple config sources
func TestConfigRoute(t *testing.T) {
routeConfig := map[string]config.Route{
"test2": config.Route{Prefix: "10.2.0.0/24", Gateway: "10.255.0.2", IPVSMethod: "masq"},
"test1": config.Route{Prefix: "10.1.0.0/24", IPVSMethod: "masq"},
"internal": config.Route{Prefix: "10.0.0.0/8", IPVSMethod: ""},
}
routes, err := configRoutes(routeConfig)
if err != nil {
t.Fatalf("configRoutes: %v\n", err)
}
if diff := pretty.Compare(testRoutes, routes); diff != "" {
t.Errorf("configRoutes incorrect:\n%s", diff)
}
}
func TestRouteLookup(t *testing.T) {
if diff := pretty.Compare(testRoutes["test1"], testRoutes.Lookup(net.IP{10, 1, 0, 1})); diff != "" {
t.Errorf("routes.Lookup 10.1.0.1:\n%s", diff)
}
if diff := pretty.Compare(testRoutes["internal"], testRoutes.Lookup(net.IP{10, 99, 0, 1})); diff != "" {
t.Errorf("routes.Lookup 10.99.0.1:\n%s", diff)
}
if diff := pretty.Compare(nil, testRoutes.Lookup(net.IP{192, 0, 2, 1})); diff != "" {
t.Errorf("routes.Lookup 192.0.2.1:\n%s", diff)
}
}