snapshot: Separate tests using root from non-root
Signed-off-by: Samuel Karp <skarp@amazon.com>
This commit is contained in:
parent
682a37f25c
commit
cacda40317
8 changed files with 46 additions and 7 deletions
|
@ -19,6 +19,7 @@ const (
|
|||
)
|
||||
|
||||
func TestBtrfs(t *testing.T) {
|
||||
testutil.RequiresRoot(t)
|
||||
device := setupBtrfsLoopbackDevice(t)
|
||||
defer removeBtrfsLoopbackDevice(t, device)
|
||||
root, err := ioutil.TempDir(device.mountPoint, "TestBtrfsPrepare-")
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
// examples we've discussed thus far. It does perform mounts, so you must run
|
||||
// as root.
|
||||
func TestSnapshotManagerBasic(t *testing.T) {
|
||||
testutil.RequiresRoot(t)
|
||||
tmpDir, err := ioutil.TempDir("", "test-sm-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -7,9 +7,11 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/containerd"
|
||||
"github.com/docker/containerd/snapshot/testutil"
|
||||
)
|
||||
|
||||
func TestSnapshotNaiveBasic(t *testing.T) {
|
||||
testutil.RequiresRoot(t)
|
||||
tmpDir, err := ioutil.TempDir("", "test-naive-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/containerd"
|
||||
"github.com/docker/containerd/snapshot/testutil"
|
||||
)
|
||||
|
||||
func TestOverlay(t *testing.T) {
|
||||
|
@ -126,9 +127,7 @@ func TestOverlayOverlayMount(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOverlayOverlayRead(t *testing.T) {
|
||||
if os.Getuid() != 0 {
|
||||
t.Skip("not running as root")
|
||||
}
|
||||
testutil.RequiresRoot(t)
|
||||
root, err := ioutil.TempDir("", "overlay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
package testutil
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var rootEnabled bool
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
|
||||
}
|
||||
|
||||
// Unmount unmounts a given mountPoint and sets t.Error if it fails
|
||||
func Unmount(t *testing.T, mountPoint string) {
|
||||
t.Log("unmount", mountPoint)
|
||||
if err := syscall.Unmount(mountPoint, 0); err != nil {
|
||||
t.Error("Could not umount", mountPoint, err)
|
||||
}
|
||||
}
|
||||
|
||||
// RequiresRoot skips tests that require root, unless the test.root flag has
|
||||
// been set
|
||||
func RequiresRoot(t *testing.T) {
|
||||
if !rootEnabled {
|
||||
t.Skip("skipping test that requires root")
|
||||
return
|
||||
}
|
||||
assert.Equal(t, 0, os.Getuid(), "This test must be run as root.")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue