Run TestSocketGet in dedicated netns

Signed-off-by: Alessandro Boch <aboch@tetrationanalytics.com>
This commit is contained in:
Alessandro Boch 2017-11-27 16:10:03 -08:00 committed by Alessandro Boch
parent a5d066db6e
commit 6e7bb56ca4
2 changed files with 25 additions and 4 deletions

View File

@ -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.")

View File

@ -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)