Skip to content

Commit

Permalink
Skip tests if not root (#12)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
theatrus authored Dec 14, 2017
1 parent da746f9 commit 9801299
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nl/down_test.go
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions nl/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl

import (
"fmt"
"os"
"testing"

"github.com/vishvananda/netlink"
Expand All @@ -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")

Expand All @@ -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")

Expand Down

0 comments on commit 9801299

Please sign in to comment.