Skip to content

Fix root tests to be ran as isolated tests #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions snapshotter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ SOURCES:=$(shell find . -name '*.go')
GOMOD := $(shell go env GOMOD)
GOSUM := $(GOMOD:.mod=.sum)
DOCKER_IMAGE_TAG?=latest
INTEG_TEST_SUFFIX := _Isolated
INTEG_TESTNAMES=$(shell docker run --rm \
--workdir="/firecracker-containerd/snapshotter" \
localhost/firecracker-containerd-test:$(DOCKER_IMAGE_TAG) \
"go test -list . | sed '$$d' | grep $(INTEG_TEST_SUFFIX)")

all: $(SUBDIRS)

Expand All @@ -30,18 +35,22 @@ install: $(SUBDIRS)
for d in $(SUBDIRS); do $(MAKE) -C $$d install; done

test:
DISABLE_ROOT_TESTS=true go test ./... $(EXTRAGOARGS)
go test ./... $(EXTRAGOARGS)

integ-test:
docker run --rm -it \
--privileged \
--ipc=host \
--volume /dev:/dev \
--volume /sys:/sys \
--volume /run/udev/control:/run/udev/control \
--workdir="/firecracker-containerd/snapshotter" \
localhost/firecracker-containerd-test:${DOCKER_IMAGE_TAG} \
"go test ./... $(EXTRAGOARGS)"
$(foreach TESTNAME,$(INTEG_TESTNAMES),\
docker run --rm -it \
--privileged \
--ipc=host \
--network=none \
--volume /dev:/dev \
--volume /run/udev/control:/run/udev/control \
--env ENABLE_ISOLATED_TESTS=1 \
--workdir="/firecracker-containerd/snapshotter" \
--init \
localhost/firecracker-containerd-naive-integ-test:$(DOCKER_IMAGE_TAG) \
"go test $(EXTRAGOARGS) -run \"^$(TESTNAME)$$\"" || exit 1; \
)

clean:
for d in $(SUBDIRS); do $(MAKE) -C $$d clean; done
Expand Down
4 changes: 2 additions & 2 deletions snapshotter/devmapper/pool_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const (
// - Change v1 file to v2 on 'thin-1'
// - Mount 'snap-1' and make sure test file is v1
// - Unmount volumes and remove all devices
func TestPoolDevice(t *testing.T) {
internal.RequiresRoot(t)
func TestPoolDevice_Isolated(t *testing.T) {
internal.RequiresIsolation(t)
logrus.SetLevel(logrus.DebugLevel)
ctx := context.Background()

Expand Down
4 changes: 2 additions & 2 deletions snapshotter/devmapper/snapshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
"github.com/firecracker-microvm/firecracker-containerd/snapshotter/pkg/losetup"
)

func TestSnapshotterSuite(t *testing.T) {
internal.RequiresRoot(t)
func TestSnapshotterSuite_Isolated(t *testing.T) {
internal.RequiresIsolation(t)
logrus.SetLevel(logrus.DebugLevel)

snapshotterFn := func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
Expand Down
8 changes: 4 additions & 4 deletions snapshotter/naive/naive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/firecracker-microvm/firecracker-containerd/internal"
)

func TestCreateImage(t *testing.T) {
internal.RequiresRoot(t)
func TestCreateImage_Isolated(t *testing.T) {
internal.RequiresIsolation(t)
snap := Snapshotter{}

tempDir, err := ioutil.TempDir("", "fc-snapshotter")
Expand Down Expand Up @@ -66,7 +66,7 @@ func createSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter,
return snap, snap.Close, nil
}

func TestSnapshotterSuite(t *testing.T) {
internal.RequiresRoot(t)
func TestSnapshotterSuite_Isolated(t *testing.T) {
internal.RequiresIsolation(t)
testsuite.SnapshotterSuite(t, "Snapshotter", createSnapshotter)
}
4 changes: 2 additions & 2 deletions snapshotter/pkg/dmsetup/dmsetup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const (
snapshotID = 2
)

func TestDMSetup(t *testing.T) {
internal.RequiresRoot(t)
func TestDMSetup_Isolated(t *testing.T) {
internal.RequiresIsolation(t)
tempDir, err := ioutil.TempDir("", "dmsetup-tests-")
require.NoErrorf(t, err, "failed to make temp dir for tests")

Expand Down
4 changes: 2 additions & 2 deletions snapshotter/pkg/losetup/losetup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestLosetup(t *testing.T) {
internal.RequiresRoot(t)
func TestLosetup_Isolated(t *testing.T) {
internal.RequiresIsolation(t)
var (
imagePath = createSparseImage(t)
loopDevice1 string
Expand Down