Merge pull request #2694 from AkihiroSuda/continuity-testutil
remove pkg/testutil/loopback_linux.go and use continuity/testutil/loopback
This commit is contained in:
		@@ -16,14 +16,7 @@
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
// FIXME: we can't put this test to the mount package:
 | 
			
		||||
// import cycle not allowed in test
 | 
			
		||||
// package github.com/containerd/containerd/mount (test)
 | 
			
		||||
//         imports github.com/containerd/containerd/pkg/testutil
 | 
			
		||||
//         imports github.com/containerd/containerd/mount
 | 
			
		||||
//
 | 
			
		||||
// NOTE: we can't have this as lookup_test (compilation fails)
 | 
			
		||||
package lookuptest
 | 
			
		||||
package mount
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
@@ -34,14 +27,16 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/containerd/containerd/mount"
 | 
			
		||||
	"github.com/containerd/containerd/pkg/testutil"
 | 
			
		||||
	// containerd/pkg/testutil has circular dependency on this mount pkg.
 | 
			
		||||
	// so we use continuity/testutil instead.
 | 
			
		||||
	"github.com/containerd/continuity/testutil"
 | 
			
		||||
	"github.com/containerd/continuity/testutil/loopback"
 | 
			
		||||
	"gotest.tools/assert"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func checkLookup(t *testing.T, fsType, mntPoint, dir string) {
 | 
			
		||||
	t.Helper()
 | 
			
		||||
	info, err := mount.Lookup(dir)
 | 
			
		||||
	info, err := Lookup(dir)
 | 
			
		||||
	assert.NilError(t, err)
 | 
			
		||||
	assert.Equal(t, fsType, info.FSType)
 | 
			
		||||
	assert.Equal(t, mntPoint, info.Mountpoint)
 | 
			
		||||
@@ -55,7 +50,7 @@ func testLookup(t *testing.T, fsType string) {
 | 
			
		||||
	}
 | 
			
		||||
	defer os.RemoveAll(mnt)
 | 
			
		||||
 | 
			
		||||
	deviceName, cleanupDevice, err := testutil.NewLoopback(100 << 20) // 100 MB
 | 
			
		||||
	deviceName, cleanupDevice, err := loopback.New(100 << 20) // 100 MB
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -31,6 +31,7 @@ import (
 | 
			
		||||
	"github.com/containerd/containerd/pkg/testutil"
 | 
			
		||||
	"github.com/containerd/containerd/snapshots"
 | 
			
		||||
	"github.com/containerd/containerd/snapshots/testsuite"
 | 
			
		||||
	"github.com/containerd/continuity/testutil/loopback"
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
@@ -51,7 +52,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
 | 
			
		||||
		if os.Getpagesize() > 4096 {
 | 
			
		||||
			loopbackSize = int64(650 << 20) // 650 MB
 | 
			
		||||
		}
 | 
			
		||||
		deviceName, cleanupDevice, err := testutil.NewLoopback(loopbackSize)
 | 
			
		||||
		deviceName, cleanupDevice, err := loopback.New(loopbackSize)
 | 
			
		||||
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, nil, err
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,7 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/containerd/containerd/pkg/testutil"
 | 
			
		||||
	"github.com/containerd/continuity/testutil/loopback"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func testOverlaySupported(t testing.TB, expected bool, mkfs ...string) {
 | 
			
		||||
@@ -35,7 +36,7 @@ func testOverlaySupported(t testing.TB, expected bool, mkfs ...string) {
 | 
			
		||||
	}
 | 
			
		||||
	defer os.RemoveAll(mnt)
 | 
			
		||||
 | 
			
		||||
	deviceName, cleanupDevice, err := testutil.NewLoopback(100 << 20) // 100 MB
 | 
			
		||||
	deviceName, cleanupDevice, err := loopback.New(100 << 20) // 100 MB
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ github.com/containerd/cgroups 5e610833b72089b37d0e615de9a92dfc043757c2
 | 
			
		||||
github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40
 | 
			
		||||
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c
 | 
			
		||||
github.com/containerd/btrfs 2e1aa0ddf94f91fa282b6ed87c23bf0d64911244
 | 
			
		||||
github.com/containerd/continuity 7f53d412b9eb1cbf744c2063185d703a0ee34700
 | 
			
		||||
github.com/containerd/continuity bd77b46c8352f74eb12c85bdc01f4b90f69d66b4
 | 
			
		||||
github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6
 | 
			
		||||
github.com/docker/go-metrics 4ea375f7759c82740c893fc030bc37088d2ec098
 | 
			
		||||
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								vendor/github.com/containerd/continuity/testutil/helpers.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								vendor/github.com/containerd/continuity/testutil/helpers.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package testutil
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"flag"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var rootEnabled bool
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										57
									
								
								vendor/github.com/containerd/continuity/testutil/helpers_unix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								vendor/github.com/containerd/continuity/testutil/helpers_unix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
// +build !windows
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package testutil
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 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 := unmountAll(mountPoint); 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.TB) {
 | 
			
		||||
	if !rootEnabled {
 | 
			
		||||
		t.Skip("skipping test that requires root")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if os.Getuid() != 0 {
 | 
			
		||||
		t.Error("This test must be run as root.")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func unmountAll(mountpoint string) error {
 | 
			
		||||
	for {
 | 
			
		||||
		if err := unix.Unmount(mountpoint, unmountFlags); err != nil {
 | 
			
		||||
			if err == unix.EINVAL {
 | 
			
		||||
				return nil
 | 
			
		||||
			}
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								vendor/github.com/containerd/continuity/testutil/helpers_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								vendor/github.com/containerd/continuity/testutil/helpers_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package testutil
 | 
			
		||||
 | 
			
		||||
import "testing"
 | 
			
		||||
 | 
			
		||||
// RequiresRoot does nothing on Windows
 | 
			
		||||
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) {
 | 
			
		||||
}
 | 
			
		||||
@@ -16,7 +16,7 @@
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package testutil
 | 
			
		||||
package loopback
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
@@ -28,8 +28,8 @@ import (
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NewLoopback creates a loopback device, and returns its device name (/dev/loopX), and its clean-up function.
 | 
			
		||||
func NewLoopback(size int64) (string, func() error, error) {
 | 
			
		||||
// New creates a loopback device, and returns its device name (/dev/loopX), and its clean-up function.
 | 
			
		||||
func New(size int64) (string, func() error, error) {
 | 
			
		||||
	// create temporary file for the disk image
 | 
			
		||||
	file, err := ioutil.TempFile("", "containerd-test-loopback")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -14,6 +14,8 @@
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package lookuptest
 | 
			
		||||
package testutil
 | 
			
		||||
 | 
			
		||||
// FIXME: without this dummy file, `make build` fails with "no buildable Go source files" error
 | 
			
		||||
import "golang.org/x/sys/unix"
 | 
			
		||||
 | 
			
		||||
const unmountFlags int = unix.MNT_DETACH
 | 
			
		||||
							
								
								
									
										21
									
								
								vendor/github.com/containerd/continuity/testutil/mount_other.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								vendor/github.com/containerd/continuity/testutil/mount_other.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
// +build !linux,!windows
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
   you may not use this file except in compliance with the License.
 | 
			
		||||
   You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
       http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
   Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
   distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
   See the License for the specific language governing permissions and
 | 
			
		||||
   limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package testutil
 | 
			
		||||
 | 
			
		||||
const unmountFlags int = 0
 | 
			
		||||
		Reference in New Issue
	
	Block a user