Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: Fix TestIsHostDevice test as non-root
Browse files Browse the repository at this point in the history
Don't Attempt to create file below `/dev` when running as non-`root`.

Move the logic into a new `TestIsHostDeviceCreateFile` test and skip
unless `root.`

Fixes #242.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Apr 23, 2018
1 parent de32be7 commit 53d73e5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion virtcontainers/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ package virtcontainers
import (
"bytes"
"fmt"
"github.com/stretchr/testify/assert"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"syscall"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsSystemMount(t *testing.T) {
Expand Down Expand Up @@ -60,8 +61,14 @@ func TestIsHostDevice(t *testing.T) {
t.Fatalf("Expected result for path %s : %v, got %v", test.mnt, test.expected, result)
}
}
}

func TestIsHostDeviceCreateFile(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip(testDisabledAsNonRoot)
}
// Create regular file in /dev

path := "/dev/foobar"
f, err := os.Create(path)
if err != nil {
Expand Down

0 comments on commit 53d73e5

Please sign in to comment.