mirror of https://github.com/vishvananda/netlink
Run TestSocketGet in dedicated netns
Signed-off-by: Alessandro Boch <aboch@tetrationanalytics.com>
This commit is contained in:
parent
a5d066db6e
commit
6e7bb56ca4
|
@ -43,6 +43,29 @@ func setUpNetlinkTest(t *testing.T) tearDownNetlinkTest {
|
|||
}
|
||||
}
|
||||
|
||||
func setUpNetlinkTestWithLoopback(t *testing.T) tearDownNetlinkTest {
|
||||
skipUnlessRoot(t)
|
||||
|
||||
runtime.LockOSThread()
|
||||
ns, err := netns.New()
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create new netns", ns)
|
||||
}
|
||||
|
||||
link, err := LinkByName("lo")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to find \"lo\" in new netns: %v", err)
|
||||
}
|
||||
if err := LinkSetUp(link); err != nil {
|
||||
t.Fatalf("Failed to bring up \"lo\" in new netns: %v", err)
|
||||
}
|
||||
|
||||
return func() {
|
||||
ns.Close()
|
||||
runtime.UnlockOSThread()
|
||||
}
|
||||
}
|
||||
|
||||
func setUpMPLSNetlinkTest(t *testing.T) tearDownNetlinkTest {
|
||||
if _, err := os.Stat("/proc/sys/net/mpls/platform_labels"); err != nil {
|
||||
t.Skip("Test requires MPLS support.")
|
||||
|
|
|
@ -5,16 +5,14 @@ package netlink
|
|||
import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSocketGet(t *testing.T) {
|
||||
if os.Getenv("TRAVIS_BUILD_DIR") != "" {
|
||||
t.Skipf("Goroutines + network namespaces == inconsistent results")
|
||||
}
|
||||
defer setUpNetlinkTestWithLoopback(t)()
|
||||
|
||||
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
Loading…
Reference in New Issue