From 84cc3e496b0d27847da5db1fe5b2d85e9604f865 Mon Sep 17 00:00:00 2001 From: "Paul \"TBBle\" Hampson" Date: Sun, 13 Dec 2020 20:51:13 +1100 Subject: [PATCH] Unify testutil.Unmount on Windows and Unix Signed-off-by: Paul "TBBle" Hampson --- pkg/testutil/helpers.go | 10 ++++++++++ pkg/testutil/helpers_unix.go | 8 -------- pkg/testutil/helpers_windows.go | 5 ----- pkg/testutil/mount_other.go | 3 ++- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pkg/testutil/helpers.go b/pkg/testutil/helpers.go index 9a9f857e2..850f51f83 100644 --- a/pkg/testutil/helpers.go +++ b/pkg/testutil/helpers.go @@ -23,6 +23,9 @@ import ( "path/filepath" "strconv" "testing" + + "github.com/containerd/containerd/mount" + "github.com/stretchr/testify/assert" ) var rootEnabled bool @@ -79,3 +82,10 @@ func DumpDirOnFailure(t *testing.T, root string) { DumpDir(t, root) } } + +// Unmount unmounts a given mountPoint and sets t.Error if it fails +func Unmount(t testing.TB, mountPoint string) { + t.Log("unmount", mountPoint) + err := mount.UnmountAll(mountPoint, umountflags) + assert.NoError(t, err) +} diff --git a/pkg/testutil/helpers_unix.go b/pkg/testutil/helpers_unix.go index 6e03a07f9..f402e44a3 100644 --- a/pkg/testutil/helpers_unix.go +++ b/pkg/testutil/helpers_unix.go @@ -23,17 +23,9 @@ import ( "os" "testing" - "github.com/containerd/containerd/mount" "github.com/stretchr/testify/assert" ) -// Unmount unmounts a given mountPoint and sets t.Error if it fails -func Unmount(t testing.TB, mountPoint string) { - t.Log("unmount", mountPoint) - err := mount.UnmountAll(mountPoint, umountflags) - assert.NoError(t, err) -} - // RequiresRoot skips tests that require root, unless the test.root flag has // been set func RequiresRoot(t testing.TB) { diff --git a/pkg/testutil/helpers_windows.go b/pkg/testutil/helpers_windows.go index 203d98771..501c3d803 100644 --- a/pkg/testutil/helpers_windows.go +++ b/pkg/testutil/helpers_windows.go @@ -25,8 +25,3 @@ func RequiresRoot(t testing.TB) { // RequiresRootM is similar to RequiresRoot but intended to be called from *testing.M. func RequiresRootM() { } - -// Unmount unmounts a given mountPoint and sets t.Error if it fails -// Does nothing on Windows -func Unmount(t *testing.T, mountPoint string) { -} diff --git a/pkg/testutil/mount_other.go b/pkg/testutil/mount_other.go index 163073bd0..b1aa7d460 100644 --- a/pkg/testutil/mount_other.go +++ b/pkg/testutil/mount_other.go @@ -1,4 +1,5 @@ -//go:build !linux && !windows +//go:build !linux +// +build !linux /* Copyright The containerd Authors.