mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Update tests to have custom routes
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
This commit is contained in:
parent
eedaf08eb8
commit
b1d26985d0
2 changed files with 17 additions and 6 deletions
|
@ -12,6 +12,10 @@ var (
|
||||||
ErrNetworkOverlaps = errors.New("requested network overlaps with existing network")
|
ErrNetworkOverlaps = errors.New("requested network overlaps with existing network")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
networkGetRoutesFct = netlink.NetworkGetRoutes
|
||||||
|
)
|
||||||
|
|
||||||
func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error {
|
func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error {
|
||||||
if len(nameservers) > 0 {
|
if len(nameservers) > 0 {
|
||||||
for _, ns := range nameservers {
|
for _, ns := range nameservers {
|
||||||
|
@ -28,7 +32,7 @@ func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckRouteOverlaps(toCheck *net.IPNet) error {
|
func CheckRouteOverlaps(toCheck *net.IPNet) error {
|
||||||
networks, err := netlink.NetworkGetRoutes()
|
networks, err := networkGetRoutesFct()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,12 +35,19 @@ func TestOverlapingNameservers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckRouteOverlaps(t *testing.T) {
|
func TestCheckRouteOverlaps(t *testing.T) {
|
||||||
routesData := []string{"10.0.2.0/32", "10.0.3.0/24", "10.0.42.0/24", "172.16.42.0/24", "192.168.142.0/24"}
|
orig := networkGetRoutesFct
|
||||||
|
defer func() {
|
||||||
|
networkGetRoutesFct = orig
|
||||||
|
}()
|
||||||
|
networkGetRoutesFct = func() ([]netlink.Route, error) {
|
||||||
|
routesData := []string{"10.0.2.0/32", "10.0.3.0/24", "10.0.42.0/24", "172.16.42.0/24", "192.168.142.0/24"}
|
||||||
|
|
||||||
routes := []netlink.Route{}
|
routes := []netlink.Route{}
|
||||||
for _, addr := range routesData {
|
for _, addr := range routesData {
|
||||||
_, netX, _ := net.ParseCIDR(addr)
|
_, netX, _ := net.ParseCIDR(addr)
|
||||||
routes = append(routes, netlink.Route{IPNet: netX})
|
routes = append(routes, netlink.Route{IPNet: netX})
|
||||||
|
}
|
||||||
|
return routes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, netX, _ := net.ParseCIDR("172.16.0.1/24")
|
_, netX, _ := net.ParseCIDR("172.16.0.1/24")
|
||||||
|
|
Loading…
Reference in a new issue