Enable extended error message reporting in tests

This causes the NETLINK_EXT_ACK socket option to be set and extended
error messages to be reported in errors. This should help debug test
failures.

Also use errors.Is to check for errors because using extended error
reporting, the errors no longer match exactly.
This commit is contained in:
Tobias Klauser 2023-10-24 13:14:21 +02:00 committed by Alessandro Boch
parent a4fcbb7aeb
commit 40e139bb96
2 changed files with 30 additions and 23 deletions

View File

@ -2048,7 +2048,7 @@ func TestLinkXdp(t *testing.T) {
if err := LinkSetXdpFd(testXdpLink, fd); err != nil {
t.Fatal(err)
}
if err := LinkSetXdpFdWithFlags(testXdpLink, fd, nl.XDP_FLAGS_UPDATE_IF_NOEXIST); err != unix.EBUSY {
if err := LinkSetXdpFdWithFlags(testXdpLink, fd, nl.XDP_FLAGS_UPDATE_IF_NOEXIST); !errors.Is(err, unix.EBUSY) {
t.Fatal(err)
}
if err := LinkSetXdpFd(testXdpLink, -1); err != nil {

View File

@ -1,3 +1,4 @@
//go:build linux
// +build linux
package netlink
@ -15,6 +16,7 @@ import (
"strings"
"testing"
"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
)
@ -214,3 +216,8 @@ func KernelVersion() (kernel, major int, err error) {
}
return
}
func TestMain(m *testing.M) {
nl.EnableErrorMessageReporting = true
os.Exit(m.Run())
}