2015-02-24 21:41:17 -05:00
|
|
|
package bridge
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-09-07 13:33:28 -04:00
|
|
|
"github.com/docker/libnetwork/testutils"
|
2015-02-24 21:41:17 -05:00
|
|
|
"github.com/vishvananda/netlink"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInterfaceDefaultName(t *testing.T) {
|
2015-09-07 13:33:28 -04:00
|
|
|
defer testutils.SetupTestOSContext(t)()
|
2015-02-24 21:41:17 -05:00
|
|
|
|
2016-05-16 14:51:40 -04:00
|
|
|
nh, err := netlink.NewHandle()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-05-22 13:56:36 -04:00
|
|
|
config := &networkConfiguration{}
|
2016-09-05 07:36:59 -04:00
|
|
|
_, err = newInterface(nh, config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("newInterface() failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.BridgeName != DefaultBridgeName {
|
2015-04-15 01:25:42 -04:00
|
|
|
t.Fatalf("Expected default interface name %q, got %q", DefaultBridgeName, config.BridgeName)
|
2015-02-24 21:41:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddressesEmptyInterface(t *testing.T) {
|
2015-09-07 13:33:28 -04:00
|
|
|
defer testutils.SetupTestOSContext(t)()
|
2015-02-24 21:41:17 -05:00
|
|
|
|
2016-05-16 14:51:40 -04:00
|
|
|
nh, err := netlink.NewHandle()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-09-05 07:36:59 -04:00
|
|
|
inf, err := newInterface(nh, &networkConfiguration{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("newInterface() failed: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-03-04 16:25:43 -05:00
|
|
|
addrv4, addrsv6, err := inf.addresses()
|
2015-02-24 21:41:17 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to get addresses of default interface: %v", err)
|
|
|
|
}
|
|
|
|
if expected := (netlink.Addr{}); addrv4 != expected {
|
|
|
|
t.Fatalf("Default interface has unexpected IPv4: %s", addrv4)
|
|
|
|
}
|
|
|
|
if len(addrsv6) != 0 {
|
|
|
|
t.Fatalf("Default interface has unexpected IPv6: %v", addrsv6)
|
|
|
|
}
|
|
|
|
}
|