|
@@ -4,6 +4,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"os"
|
|
"os"
|
|
"os/exec"
|
|
"os/exec"
|
|
|
|
+ "path/filepath"
|
|
"regexp"
|
|
"regexp"
|
|
"sort"
|
|
"sort"
|
|
"strings"
|
|
"strings"
|
|
@@ -424,6 +425,48 @@ func TestCreateVolume(t *testing.T) {
|
|
logDone("run - create docker mangaed volume")
|
|
logDone("run - create docker mangaed volume")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Test that creating a volume with a symlink in its path works correctly. Test for #5152.
|
|
|
|
+// Note that this bug happens only with symlinks with a target that starts with '/'.
|
|
|
|
+func TestVolumeWithSymlink(t *testing.T) {
|
|
|
|
+ buildDirectory := filepath.Join(workingDirectory, "run_tests", "TestVolumeWithSymlink")
|
|
|
|
+ buildCmd := exec.Command(dockerBinary, "build", "-t", "docker-test-volumewithsymlink", ".")
|
|
|
|
+ buildCmd.Dir = buildDirectory
|
|
|
|
+ err := buildCmd.Run()
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal("could not build 'docker-test-volumewithsymlink': %v", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cmd := exec.Command(dockerBinary, "run", "-v", "/bar/foo", "--name", "test-volumewithsymlink", "docker-test-volumewithsymlink", "sh", "-c", "mount | grep -q /foo/foo")
|
|
|
|
+ exitCode, err := runCommand(cmd)
|
|
|
|
+ if err != nil || exitCode != 0 {
|
|
|
|
+ t.Fatal("[run] err: %v, exitcode: %d", err, exitCode)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var volPath string
|
|
|
|
+ cmd = exec.Command(dockerBinary, "inspect", "-f", "{{range .Volumes}}{{.}}{{end}}", "test-volumewithsymlink")
|
|
|
|
+ volPath, exitCode, err = runCommandWithOutput(cmd)
|
|
|
|
+ if err != nil || exitCode != 0 {
|
|
|
|
+ t.Fatal("[inspect] err: %v, exitcode: %d", err, exitCode)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cmd = exec.Command(dockerBinary, "rm", "-v", "test-volumewithsymlink")
|
|
|
|
+ exitCode, err = runCommand(cmd)
|
|
|
|
+ if err != nil || exitCode != 0 {
|
|
|
|
+ t.Fatal("[rm] err: %v, exitcode: %d", err, exitCode)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ f, err := os.Open(volPath)
|
|
|
|
+ defer f.Close()
|
|
|
|
+ if !os.IsNotExist(err) {
|
|
|
|
+ t.Fatal("[open] (expecting 'file does not exist' error) err: %v, volPath: %s", err, volPath)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ deleteImages("docker-test-volumewithsymlink")
|
|
|
|
+ deleteAllContainers()
|
|
|
|
+
|
|
|
|
+ logDone("run - volume with symlink")
|
|
|
|
+}
|
|
|
|
+
|
|
func TestExitCode(t *testing.T) {
|
|
func TestExitCode(t *testing.T) {
|
|
cmd := exec.Command(dockerBinary, "run", "busybox", "/bin/sh", "-c", "exit 72")
|
|
cmd := exec.Command(dockerBinary, "run", "busybox", "/bin/sh", "-c", "exit 72")
|
|
|
|
|