diff options
author | insomniac <insomniacslk@users.noreply.github.com> | 2019-04-15 09:33:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-15 09:33:08 +0100 |
commit | ac4db3f5fb61a34cf65d81fb4efe6e3d2627b461 (patch) | |
tree | e85597d906594cb21b91c7f4eceeffe37c8cd16d /netboot/rtnetlink_linux_test.go | |
parent | eea1149bcb0a49e5203db64137de7d48ce78c18b (diff) |
Replace vishvananda/netlink with jsimonetti/rtnetlink (#271)
Fixes #257
And saves ~100kb.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Diffstat (limited to 'netboot/rtnetlink_linux_test.go')
-rw-r--r-- | netboot/rtnetlink_linux_test.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/netboot/rtnetlink_linux_test.go b/netboot/rtnetlink_linux_test.go new file mode 100644 index 0000000..860ea0f --- /dev/null +++ b/netboot/rtnetlink_linux_test.go @@ -0,0 +1,82 @@ +//+build integration + +package netboot + +import ( + "net" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/sys/unix" +) + +// integration tests that require Linux with a properly working rtnetlink +// interface, and the existence of an "eth0" interface. +// WARNING: these tests may improperly configure your network interfaces and +// routing, so be careful before running them. Privileged access and integration +// build tag required to run them. + +var ( + testIfname = "eth0" +) + +func TestInit(t *testing.T) { + var r RTNL + err := r.init() + assert.NoError(t, err) + require.NotNil(t, r.conn) + r.Close() +} + +func TestClose(t *testing.T) { + var r RTNL + err := r.init() + assert.NoError(t, err) + require.NotNil(t, r.conn) + r.Close() + require.Nil(t, r.conn) +} + +func TestGetLinkState(t *testing.T) { + var r RTNL + defer r.Close() + + iface, err := net.InterfaceByName(testIfname) + require.NoError(t, err) + _, err = r.GetLinkState(iface.Index) + require.NoError(t, err) +} + +func TestSetLinkState(t *testing.T) { + var r RTNL + defer r.Close() + + iface, err := net.InterfaceByName(testIfname) + require.NoError(t, err) + err = r.SetLinkState(iface.Index, true) + require.NoError(t, err) +} + +func Test_getFamily(t *testing.T) { + require.Equal(t, unix.AF_INET, getFamily(net.IPv4zero)) + require.Equal(t, unix.AF_INET, getFamily(net.IPv4bcast)) + require.Equal(t, unix.AF_INET, getFamily(net.IPv4allrouter)) + + require.Equal(t, unix.AF_INET6, getFamily(net.IPv6zero)) + require.Equal(t, unix.AF_INET6, getFamily(net.IPv6loopback)) + require.Equal(t, unix.AF_INET6, getFamily(net.IPv6linklocalallrouters)) +} + +func TestSetAddr(t *testing.T) { + var r RTNL + defer r.Close() + iface, err := net.InterfaceByName(testIfname) + require.NoError(t, err) + + a := net.IPNet{IP: net.ParseIP("10.0.123.1"), Mask: net.IPv4Mask(255, 255, 255, 0)} + err = r.SetAddr(iface.Index, a) + require.NoError(t, err) + // TODO implement GetAddr to further validate this, and minimize the effect + // of concurrent tests that may invalidate this check. +} |