mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6424c7a875
Fix all golint warnings, mostly by making exported types internal. Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
package bridge
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/docker/libnetwork"
|
|
"github.com/vishvananda/netlink"
|
|
)
|
|
|
|
func setupTestInterface(t *testing.T) *bridgeInterface {
|
|
br := &bridgeInterface{
|
|
Config: &Configuration{
|
|
BridgeName: DefaultBridgeName,
|
|
},
|
|
}
|
|
if err := setupDevice(br); err != nil {
|
|
t.Fatalf("Bridge creation failed: %v", err)
|
|
}
|
|
return br
|
|
}
|
|
|
|
func TestSetupBridgeIPv4Fixed(t *testing.T) {
|
|
defer libnetwork.SetupTestNetNS(t)()
|
|
|
|
ip, netw, err := net.ParseCIDR("192.168.1.1/24")
|
|
if err != nil {
|
|
t.Fatalf("Failed to parse bridge IPv4: %v", err)
|
|
}
|
|
|
|
br := setupTestInterface(t)
|
|
br.Config.AddressIPv4 = &net.IPNet{IP: ip, Mask: netw.Mask}
|
|
if err := setupBridgeIPv4(br); err != nil {
|
|
t.Fatalf("Failed to setup bridge IPv4: %v", err)
|
|
}
|
|
|
|
addrsv4, err := netlink.AddrList(br.Link, netlink.FAMILY_V4)
|
|
if err != nil {
|
|
t.Fatalf("Failed to list device IPv4 addresses: %v", err)
|
|
}
|
|
|
|
var found bool
|
|
for _, addr := range addrsv4 {
|
|
if br.Config.AddressIPv4.String() == addr.IPNet.String() {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
t.Fatalf("Bridge device does not have requested IPv4 address %v", br.Config.AddressIPv4)
|
|
}
|
|
}
|
|
|
|
func TestSetupBridgeIPv4Auto(t *testing.T) {
|
|
defer libnetwork.SetupTestNetNS(t)()
|
|
|
|
br := setupTestInterface(t)
|
|
if err := setupBridgeIPv4(br); err != nil {
|
|
t.Fatalf("Failed to setup bridge IPv4: %v", err)
|
|
}
|
|
|
|
addrsv4, err := netlink.AddrList(br.Link, netlink.FAMILY_V4)
|
|
if err != nil {
|
|
t.Fatalf("Failed to list device IPv4 addresses: %v", err)
|
|
}
|
|
|
|
var found bool
|
|
for _, addr := range addrsv4 {
|
|
if bridgeNetworks[0].String() == addr.IPNet.String() {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
t.Fatalf("Bridge device does not have the automatic IPv4 address %v", bridgeNetworks[0].String())
|
|
}
|
|
}
|