TestAddRoute tests Stack.AddRoute
(t *testing.T)
| 4407 | |
| 4408 | // TestAddRoute tests Stack.AddRoute |
| 4409 | func TestAddRoute(t *testing.T) { |
| 4410 | s := stack.New(stack.Options{}) |
| 4411 | |
| 4412 | subnet1, err := tcpip.NewSubnet(tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), tcpip.MaskFrom("\x00\x00\x00\x00")) |
| 4413 | if err != nil { |
| 4414 | t.Fatal(err) |
| 4415 | } |
| 4416 | |
| 4417 | subnet2, err := tcpip.NewSubnet(tcpip.AddrFromSlice([]byte("\x01\x00\x00\x00")), tcpip.MaskFrom("\xff\x00\x00\x00")) |
| 4418 | if err != nil { |
| 4419 | t.Fatal(err) |
| 4420 | } |
| 4421 | |
| 4422 | expected := []tcpip.Route{ |
| 4423 | {Destination: subnet2, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 1}, |
| 4424 | {Destination: subnet1, Gateway: tcpip.AddrFromSlice([]byte("\x00\x00\x00\x00")), NIC: 1}, |
| 4425 | } |
| 4426 | |
| 4427 | // Initialize the route table with one route. |
| 4428 | s.SetRouteTable([]tcpip.Route{expected[0]}) |
| 4429 | |
| 4430 | // Add another route. |
| 4431 | s.AddRoute(expected[1]) |
| 4432 | |
| 4433 | rt := s.GetRouteTable() |
| 4434 | if got, want := len(rt), len(expected); got != want { |
| 4435 | t.Fatalf("Unexpected route table length got = %d, want = %d", got, want) |
| 4436 | } |
| 4437 | for i, route := range rt { |
| 4438 | if got, want := route, expected[i]; !got.Equal(want) { |
| 4439 | t.Fatalf("Unexpected route got = %#v, want = %#v", got, want) |
| 4440 | } |
| 4441 | } |
| 4442 | } |
| 4443 | |
| 4444 | // TestRemoveRoutes tests Stack.RemoveRoutes |
| 4445 | func TestRemoveRoutes(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…