The replacement is also deprecated, but at least returns a strong type,
which may help transitioning to using an api-client for these, and
removing one abstraction at a time.
Also rewriting the TestContainerAPIDeleteRemoveVolume to use the API
client (as it's part of the API suite), and touched-up the
TestRunMountShmMqueueFromHost test a bit.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -1014,17 +1014,25 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveLinks(c *testing.T) {
|
| 1014 | 1014 |
func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
|
| 1015 | 1015 |
testRequires(c, testEnv.IsLocalDaemon) |
| 1016 | 1016 |
|
| 1017 |
- vol := "/testvolume" |
|
| 1017 |
+ testVol := "/testvolume" |
|
| 1018 | 1018 |
if testEnv.DaemonInfo.OSType == "windows" {
|
| 1019 |
- vol = `c:\testvolume` |
|
| 1019 |
+ testVol = `c:\testvolume` |
|
| 1020 | 1020 |
} |
| 1021 | 1021 |
|
| 1022 |
- id := runSleepingContainer(c, "-v", vol) |
|
| 1022 |
+ id := runSleepingContainer(c, "-v", testVol) |
|
| 1023 | 1023 |
cli.WaitRun(c, id) |
| 1024 | 1024 |
|
| 1025 |
- source, err := inspectMountSourceField(id, vol) |
|
| 1025 |
+ apiClient, err := client.NewClientWithOpts(client.FromEnv) |
|
| 1026 | 1026 |
assert.NilError(c, err) |
| 1027 |
- _, err = os.Stat(source) |
|
| 1027 |
+ defer apiClient.Close() |
|
| 1028 |
+ |
|
| 1029 |
+ ctrInspect, err := apiClient.ContainerInspect(testutil.GetContext(c), id) |
|
| 1030 |
+ assert.NilError(c, err) |
|
| 1031 |
+ assert.Assert(c, is.Len(ctrInspect.Mounts, 1), "expected to have 1 mount") |
|
| 1032 |
+ mnt := ctrInspect.Mounts[0] |
|
| 1033 |
+ assert.Equal(c, mnt.Destination, testVol) |
|
| 1034 |
+ |
|
| 1035 |
+ _, err = os.Stat(mnt.Source) |
|
| 1028 | 1036 |
assert.NilError(c, err) |
| 1029 | 1037 |
|
| 1030 | 1038 |
removeOptions := container.RemoveOptions{
|
| ... | ... |
@@ -1032,14 +1040,10 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
|
| 1032 | 1032 |
RemoveVolumes: true, |
| 1033 | 1033 |
} |
| 1034 | 1034 |
|
| 1035 |
- apiClient, err := client.NewClientWithOpts(client.FromEnv) |
|
| 1036 |
- assert.NilError(c, err) |
|
| 1037 |
- defer apiClient.Close() |
|
| 1038 |
- |
|
| 1039 | 1035 |
err = apiClient.ContainerRemove(testutil.GetContext(c), id, removeOptions) |
| 1040 | 1036 |
assert.NilError(c, err) |
| 1041 | 1037 |
|
| 1042 |
- _, err = os.Stat(source) |
|
| 1038 |
+ _, err = os.Stat(mnt.Source) |
|
| 1043 | 1039 |
assert.Assert(c, os.IsNotExist(err), "expected to get ErrNotExist error, got %v", err) |
| 1044 | 1040 |
} |
| 1045 | 1041 |
|
| ... | ... |
@@ -152,10 +152,10 @@ func (s *DockerCLICreateSuite) TestCreateVolumesCreated(c *testing.T) {
|
| 152 | 152 |
const name = "test_create_volume" |
| 153 | 153 |
cli.DockerCmd(c, "create", "--name", name, "-v", prefix+slash+"foo", "busybox") |
| 154 | 154 |
|
| 155 |
- dir, err := inspectMountSourceField(name, prefix+slash+"foo") |
|
| 155 |
+ mnt, err := inspectMountPoint(name, prefix+slash+"foo") |
|
| 156 | 156 |
assert.Assert(c, err == nil, "Error getting volume host path: %q", err) |
| 157 | 157 |
|
| 158 |
- if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
|
|
| 158 |
+ if _, err := os.Stat(mnt.Source); err != nil && os.IsNotExist(err) {
|
|
| 159 | 159 |
c.Fatalf("Volume was not created")
|
| 160 | 160 |
} |
| 161 | 161 |
if err != nil {
|
| ... | ... |
@@ -76,7 +76,7 @@ func (s *DockerCLIRestartSuite) TestRestartWithVolumes(c *testing.T) {
|
| 76 | 76 |
out = strings.Trim(out, " \n\r") |
| 77 | 77 |
assert.Equal(c, out, "1") |
| 78 | 78 |
|
| 79 |
- source, err := inspectMountSourceField(cID, prefix+slash+"test") |
|
| 79 |
+ mnt, err := inspectMountPoint(cID, prefix+slash+"test") |
|
| 80 | 80 |
assert.NilError(c, err) |
| 81 | 81 |
|
| 82 | 82 |
cli.DockerCmd(c, "restart", cID) |
| ... | ... |
@@ -86,9 +86,9 @@ func (s *DockerCLIRestartSuite) TestRestartWithVolumes(c *testing.T) {
|
| 86 | 86 |
out = strings.Trim(out, " \n\r") |
| 87 | 87 |
assert.Equal(c, out, "1") |
| 88 | 88 |
|
| 89 |
- sourceAfterRestart, err := inspectMountSourceField(cID, prefix+slash+"test") |
|
| 89 |
+ mountAfterRestart, err := inspectMountPoint(cID, prefix+slash+"test") |
|
| 90 | 90 |
assert.NilError(c, err) |
| 91 |
- assert.Equal(c, source, sourceAfterRestart) |
|
| 91 |
+ assert.Equal(c, mnt.Source, mountAfterRestart.Source) |
|
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 | 94 |
func (s *DockerCLIRestartSuite) TestRestartDisconnectedContainer(c *testing.T) {
|
| ... | ... |
@@ -639,7 +639,7 @@ func (s *DockerCLIRunSuite) TestRunCreateVolumeWithSymlink(c *testing.T) {
|
| 639 | 639 |
c.Fatalf("[run] err: %v, exitcode: %d", err, exitCode)
|
| 640 | 640 |
} |
| 641 | 641 |
|
| 642 |
- volPath, err := inspectMountSourceField("test-createvolumewithsymlink", "/bar/foo")
|
|
| 642 |
+ mnt, err := inspectMountPoint("test-createvolumewithsymlink", "/bar/foo")
|
|
| 643 | 643 |
assert.NilError(c, err) |
| 644 | 644 |
|
| 645 | 645 |
_, exitCode, err = dockerCmdWithError("rm", "-v", "test-createvolumewithsymlink")
|
| ... | ... |
@@ -647,9 +647,9 @@ func (s *DockerCLIRunSuite) TestRunCreateVolumeWithSymlink(c *testing.T) {
|
| 647 | 647 |
c.Fatalf("[rm] err: %v, exitcode: %d", err, exitCode)
|
| 648 | 648 |
} |
| 649 | 649 |
|
| 650 |
- _, err = os.Stat(volPath) |
|
| 650 |
+ _, err = os.Stat(mnt.Source) |
|
| 651 | 651 |
if !os.IsNotExist(err) {
|
| 652 |
- c.Fatalf("[open] (expecting 'file does not exist' error) err: %v, volPath: %s", err, volPath)
|
|
| 652 |
+ c.Fatalf("[open] (expecting 'file does not exist' error) err: %v, mnt.Source: %s", err, mnt.Source)
|
|
| 653 | 653 |
} |
| 654 | 654 |
} |
| 655 | 655 |
|
| ... | ... |
@@ -2109,26 +2109,26 @@ func (s *DockerCLIRunSuite) TestRunVolumesCleanPaths(c *testing.T) {
|
| 2109 | 2109 |
VOLUME `+prefix+`/foo/`)) |
| 2110 | 2110 |
cli.DockerCmd(c, "run", "-v", prefix+"/foo", "-v", prefix+"/bar/", "--name", "dark_helmet", "run_volumes_clean_paths") |
| 2111 | 2111 |
|
| 2112 |
- out, err := inspectMountSourceField("dark_helmet", prefix+slash+"foo"+slash)
|
|
| 2112 |
+ mnt, err := inspectMountPoint("dark_helmet", prefix+slash+"foo"+slash)
|
|
| 2113 | 2113 |
if !errors.Is(err, errMountNotFound) {
|
| 2114 |
- c.Fatalf("Found unexpected volume entry for '%s/foo/' in volumes\n%q", prefix, out)
|
|
| 2114 |
+ c.Fatalf("Found unexpected volume entry for '%s/foo/' in volumes\n%q", prefix, mnt.Source)
|
|
| 2115 | 2115 |
} |
| 2116 | 2116 |
|
| 2117 |
- out, err = inspectMountSourceField("dark_helmet", prefix+slash+`foo`)
|
|
| 2117 |
+ mnt, err = inspectMountPoint("dark_helmet", prefix+slash+`foo`)
|
|
| 2118 | 2118 |
assert.NilError(c, err) |
| 2119 |
- if !strings.Contains(strings.ToLower(out), strings.ToLower(testEnv.PlatformDefaults.VolumesConfigPath)) {
|
|
| 2120 |
- c.Fatalf("Volume was not defined for %s/foo\n%q", prefix, out)
|
|
| 2119 |
+ if !strings.Contains(strings.ToLower(mnt.Source), strings.ToLower(testEnv.PlatformDefaults.VolumesConfigPath)) {
|
|
| 2120 |
+ c.Fatalf("Volume was not defined for %s/foo\n%q", prefix, mnt.Source)
|
|
| 2121 | 2121 |
} |
| 2122 | 2122 |
|
| 2123 |
- out, err = inspectMountSourceField("dark_helmet", prefix+slash+"bar"+slash)
|
|
| 2123 |
+ mnt, err = inspectMountPoint("dark_helmet", prefix+slash+"bar"+slash)
|
|
| 2124 | 2124 |
if !errors.Is(err, errMountNotFound) {
|
| 2125 |
- c.Fatalf("Found unexpected volume entry for '%s/bar/' in volumes\n%q", prefix, out)
|
|
| 2125 |
+ c.Fatalf("Found unexpected volume entry for '%s/bar/' in volumes\n%q", prefix, mnt.Source)
|
|
| 2126 | 2126 |
} |
| 2127 | 2127 |
|
| 2128 |
- out, err = inspectMountSourceField("dark_helmet", prefix+slash+"bar")
|
|
| 2128 |
+ mnt, err = inspectMountPoint("dark_helmet", prefix+slash+"bar")
|
|
| 2129 | 2129 |
assert.NilError(c, err) |
| 2130 |
- if !strings.Contains(strings.ToLower(out), strings.ToLower(testEnv.PlatformDefaults.VolumesConfigPath)) {
|
|
| 2131 |
- c.Fatalf("Volume was not defined for %s/bar\n%q", prefix, out)
|
|
| 2130 |
+ if !strings.Contains(strings.ToLower(mnt.Source), strings.ToLower(testEnv.PlatformDefaults.VolumesConfigPath)) {
|
|
| 2131 |
+ c.Fatalf("Volume was not defined for %s/bar\n%q", prefix, mnt.Source)
|
|
| 2132 | 2132 |
} |
| 2133 | 2133 |
} |
| 2134 | 2134 |
|
| ... | ... |
@@ -2286,23 +2286,22 @@ func (s *DockerCLIRunSuite) TestRunMountShmMqueueFromHost(c *testing.T) {
|
| 2286 | 2286 |
testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux, NotUserNamespace) |
| 2287 | 2287 |
|
| 2288 | 2288 |
cli.DockerCmd(c, "run", "-d", "--name", "shmfromhost", "-v", "/dev/shm:/dev/shm", "-v", "/dev/mqueue:/dev/mqueue", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && touch /dev/mqueue/toto && top") |
| 2289 |
- defer os.Remove("/dev/mqueue/toto")
|
|
| 2290 |
- defer os.Remove("/dev/shm/test")
|
|
| 2291 |
- volPath, err := inspectMountSourceField("shmfromhost", "/dev/shm")
|
|
| 2289 |
+ c.Cleanup(func() {
|
|
| 2290 |
+ err := os.Remove("/dev/shm/test")
|
|
| 2291 |
+ assert.Check(c, err == nil || errors.Is(err, os.ErrNotExist)) |
|
| 2292 |
+ err = os.Remove("/dev/mqueue/toto")
|
|
| 2293 |
+ assert.Check(c, err == nil || errors.Is(err, os.ErrNotExist)) |
|
| 2294 |
+ }) |
|
| 2295 |
+ mnt, err := inspectMountPoint("shmfromhost", "/dev/shm")
|
|
| 2292 | 2296 |
assert.NilError(c, err) |
| 2293 |
- if volPath != "/dev/shm" {
|
|
| 2294 |
- c.Fatalf("volumePath should have been /dev/shm, was %s", volPath)
|
|
| 2295 |
- } |
|
| 2297 |
+ assert.Equal(c, mnt.Source, "/dev/shm") |
|
| 2296 | 2298 |
|
| 2297 | 2299 |
out := cli.DockerCmd(c, "run", "--name", "ipchost", "--ipc", "host", "busybox", "cat", "/dev/shm/test").Combined() |
| 2298 |
- if out != "test" {
|
|
| 2299 |
- c.Fatalf("Output of /dev/shm/test expected test but found: %s", out)
|
|
| 2300 |
- } |
|
| 2300 |
+ assert.Equal(c, out, "test", "unexpected content for /dev/shm/test") |
|
| 2301 | 2301 |
|
| 2302 | 2302 |
// Check that the mq was created |
| 2303 |
- if _, err := os.Stat("/dev/mqueue/toto"); err != nil {
|
|
| 2304 |
- c.Fatalf("Failed to confirm '/dev/mqueue/toto' presence on host: %s", err.Error())
|
|
| 2305 |
- } |
|
| 2303 |
+ _, err = os.Stat("/dev/mqueue/toto")
|
|
| 2304 |
+ assert.NilError(c, err, "failed to confirm '/dev/mqueue/toto' presence on host") |
|
| 2306 | 2305 |
} |
| 2307 | 2306 |
|
| 2308 | 2307 |
func (s *DockerCLIRunSuite) TestContainerNetworkMode(c *testing.T) {
|
| ... | ... |
@@ -102,15 +102,6 @@ func inspectFieldJSON(t *testing.T, name, field string) string {
|
| 102 | 102 |
return out |
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 |
-// Deprecated: use cli.Docker |
|
| 106 |
-func inspectMountSourceField(name, destination string) (string, error) {
|
|
| 107 |
- m, err := inspectMountPoint(name, destination) |
|
| 108 |
- if err != nil {
|
|
| 109 |
- return "", err |
|
| 110 |
- } |
|
| 111 |
- return m.Source, nil |
|
| 112 |
-} |
|
| 113 |
- |
|
| 114 | 105 |
var errMountNotFound = errors.New("mount point not found")
|
| 115 | 106 |
|
| 116 | 107 |
// Deprecated: use cli.Docker |