mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-16 16:32:03 +00:00
virtcontainers: Fix TestIsHostDevice test as non-root
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 <james.o.hunt@intel.com>
This commit is contained in:
parent
de32be7eed
commit
53d73e56e0
@ -8,7 +8,6 @@ package virtcontainers
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -16,6 +15,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsSystemMount(t *testing.T) {
|
func TestIsSystemMount(t *testing.T) {
|
||||||
@ -60,8 +61,14 @@ func TestIsHostDevice(t *testing.T) {
|
|||||||
t.Fatalf("Expected result for path %s : %v, got %v", test.mnt, test.expected, result)
|
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
|
// Create regular file in /dev
|
||||||
|
|
||||||
path := "/dev/foobar"
|
path := "/dev/foobar"
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user