Example #1
0
func TestChangeInterfaceName(t *testing.T) {
	teardown := setUp(t)
	defer teardown()

	netlink.LinkAdd(&netlink.Dummy{netlink.LinkAttrs{Name: "foo1"}})
	err := ChangeInterfaceName("foo1", "eth42")
	if err != nil {
		t.Fatal(err)
	}
}
Example #2
0
// Each test that calls setUp runs in it's own netns
func setUp(t *testing.T) tearDown {
	// lock thread since the namespace is thread local
	runtime.LockOSThread()
	var err error
	ns, err := netns.New()
	if err != nil {
		t.Fatal("Failed to create newns", ns)
	}

	netlink.LinkAdd(&netlink.Dummy{netlink.LinkAttrs{Name: testIface}})

	return func() {
		ns.Close()
		runtime.UnlockOSThread()
	}
}
Example #3
0
func TestSetInterfaceInNamespaceFd(t *testing.T) {
	teardown := setUp(t)
	defer teardown()

	newns, err := netns.New()
	if err != nil {
		t.Fatal("Failed to create newns")
	}
	defer newns.Close()

	netlink.LinkAdd(&netlink.Dummy{netlink.LinkAttrs{Name: "foo2"}})

	err = SetInterfaceInNamespaceFd("foo2", uintptr(newns))
	if err != nil {
		t.Fatal(err)
	}

	_, err = netlink.LinkByName("bar")
	if err == nil {
		t.Fatal("Link foo2 is still in newns")
	}
}