router_windows_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // +build windows
  2. // Copyright 2015 flannel authors
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. package routing
  16. import (
  17. "net"
  18. "testing"
  19. "github.com/coreos/flannel/pkg/ip"
  20. )
  21. func TestGetAllRoutes(t *testing.T) {
  22. router := RouterWindows{}
  23. routes, err := router.GetAllRoutes()
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. if len(routes) == 0 {
  28. t.Fatal("len(routes) == 0")
  29. }
  30. }
  31. func TestCreateAndRemoveRoute(t *testing.T) {
  32. defaultInterface, err := ip.GetDefaultGatewayInterface()
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. router := RouterWindows{}
  37. allRoutes, err := router.GetAllRoutes()
  38. if err != nil {
  39. t.Fatal(err)
  40. }
  41. if len(allRoutes) == 0 {
  42. t.Fatal("len(routes) == 0")
  43. }
  44. destinationSubnet := allRoutes[0].DestinationSubnet
  45. gatewayAddress := net.ParseIP("192.168.199.123")
  46. routes, err := router.GetRoutesFromInterfaceToSubnet(defaultInterface.Index, destinationSubnet)
  47. if err != nil {
  48. t.Fatal(err)
  49. }
  50. firstRouteLen := len(routes)
  51. if len(routes) == 0 {
  52. t.Fatal("len(routes) == 0")
  53. }
  54. err = router.CreateRoute(defaultInterface.Index, destinationSubnet, gatewayAddress)
  55. if err != nil {
  56. t.Fatal(err)
  57. }
  58. routes, err = router.GetRoutesFromInterfaceToSubnet(defaultInterface.Index, destinationSubnet)
  59. if err != nil {
  60. t.Fatal(err)
  61. }
  62. expectedLen := firstRouteLen + 1
  63. givenLen := len(routes)
  64. if givenLen != expectedLen {
  65. t.Fatalf("givenLen:%d != expectedLen:%d", givenLen, expectedLen)
  66. }
  67. err = router.DeleteRoute(defaultInterface.Index, destinationSubnet, gatewayAddress)
  68. if err != nil {
  69. t.Fatal(err)
  70. }
  71. routes, err = router.GetRoutesFromInterfaceToSubnet(defaultInterface.Index, destinationSubnet)
  72. if err != nil {
  73. t.Fatal(err)
  74. }
  75. if len(routes) != firstRouteLen {
  76. t.Fatal("len(routes) != startRouteLen")
  77. }
  78. }