From 980129912530865fdca46d38f8567527593f49b6 Mon Sep 17 00:00:00 2001 From: Yann Ramin Date: Thu, 14 Dec 2017 10:15:47 -0800 Subject: [PATCH] Skip tests if not root (#12) This should allow running locally without requiring capabilities flags or root. Note that I'm not actually checking for capabilities and just for uid = 0 to determine if I should skip or not. --- nl/down_test.go | 11 +++++++++++ nl/up_test.go | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/nl/down_test.go b/nl/down_test.go index aa0467a..a3126bb 100644 --- a/nl/down_test.go +++ b/nl/down_test.go @@ -1,12 +1,18 @@ package nl import ( + "os" "testing" "github.com/vishvananda/netlink" ) func TestDownInterface(t *testing.T) { + if os.Getuid() != 0 { + t.Skip("Test requires root or network capabilities - skipped") + return + } + CreateTestInterface("lyft3") defer RemoveInterface("lyft3") @@ -20,6 +26,11 @@ func TestDownInterface(t *testing.T) { } func TestRemoveInterface(t *testing.T) { + if os.Getuid() != 0 { + t.Skip("Test requires root or network capabilities - skipped") + return + } + CreateTestInterface("lyft4") if err := RemoveInterface("lyft4"); err != nil { diff --git a/nl/up_test.go b/nl/up_test.go index 9dc1fe0..3ebc06a 100644 --- a/nl/up_test.go +++ b/nl/up_test.go @@ -2,6 +2,7 @@ package nl import ( "fmt" + "os" "testing" "github.com/vishvananda/netlink" @@ -24,6 +25,11 @@ func CreateTestInterface(name string) { } func TestUpInterface(t *testing.T) { + if os.Getuid() != 0 { + t.Skip("Test requires root or network capabilities - skipped") + return + } + CreateTestInterface("lyft1") defer RemoveInterface("lyft1") @@ -33,6 +39,11 @@ func TestUpInterface(t *testing.T) { } func TestUpInterfacePoll(t *testing.T) { + if os.Getuid() != 0 { + t.Skip("Test requires root or network capabilities - skipped") + return + } + CreateTestInterface("lyft2") defer RemoveInterface("lyft2")