Browse code

Break out non-Windows sys/mount usage into helper

Rather than bifurcate the test completely, this lets us keep the test
intact with a small function wrapper to allow the compiler to build the
code that'll never be called on Windows, on Windows.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>

Paul "TBBle" Hampson authored on 2020/11/05 23:23:49
Showing 3 changed files
... ...
@@ -30,7 +30,6 @@ import (
30 30
 	"github.com/docker/docker/testutil/request"
31 31
 	"github.com/docker/docker/volume"
32 32
 	"github.com/docker/go-connections/nat"
33
-	"github.com/moby/sys/mount"
34 33
 	"gotest.tools/v3/assert"
35 34
 	is "gotest.tools/v3/assert/cmp"
36 35
 	"gotest.tools/v3/poll"
... ...
@@ -2056,7 +2055,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) {
2056 2056
 			assert.NilError(c, err)
2057 2057
 			defer os.RemoveAll(tmpDir3)
2058 2058
 
2059
-			assert.Assert(c, mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared") == nil)
2059
+			assert.Assert(c, mountWrapper(tmpDir3, tmpDir3, "none", "bind,shared") == nil)
2060 2060
 
2061 2061
 			cases = append(cases, []testCase{
2062 2062
 				{
2063 2063
new file mode 100644
... ...
@@ -0,0 +1,9 @@
0
+// +build !windows
1
+
2
+package main
3
+
4
+import "github.com/moby/sys/mount"
5
+
6
+func mountWrapper(device, target, mType, options string) error {
7
+	return mount.Mount(device, target, mType, options)
8
+}
... ...
@@ -15,6 +15,7 @@ import (
15 15
 	"github.com/docker/docker/api/types"
16 16
 	"github.com/docker/docker/api/types/container"
17 17
 	"github.com/docker/docker/api/types/mount"
18
+	"github.com/pkg/errors"
18 19
 	"gotest.tools/v3/assert"
19 20
 	is "gotest.tools/v3/assert/cmp"
20 21
 )
... ...
@@ -75,3 +76,8 @@ func (s *DockerSuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T) {
75 75
 	assert.NilError(c, err)
76 76
 	assert.Check(c, is.Equal(text, strings.TrimSpace(string(b))))
77 77
 }
78
+
79
+func mountWrapper(device, target, mType, options string) error {
80
+	// This should never be called.
81
+	return errors.Errorf("there is no implementation of Mount on this platform")
82
+}