2021-05-25 19:48:54 -04:00
|
|
|
// +build linux
|
|
|
|
|
2015-02-24 21:41:17 -05:00
|
|
|
package bridge
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/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)
|
|
|
|
}
|
|
|
|
|
2016-09-17 01:40:44 -04:00
|
|
|
addrsv4, 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)
|
|
|
|
}
|
2016-09-17 01:40:44 -04:00
|
|
|
if len(addrsv4) != 0 {
|
|
|
|
t.Fatalf("Default interface has unexpected IPv4: %s", addrsv4)
|
2015-02-24 21:41:17 -05:00
|
|
|
}
|
|
|
|
if len(addrsv6) != 0 {
|
|
|
|
t.Fatalf("Default interface has unexpected IPv6: %v", addrsv6)
|
|
|
|
}
|
|
|
|
}
|