Handles missed comments in PR#10622 and adds an API test to validate
error returned properly for duplicate bind mounts for the same
container target path.
Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)
| ... | ... |
@@ -162,6 +162,43 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
|
| 162 | 162 |
logDone("container REST API - check volume binds on start")
|
| 163 | 163 |
} |
| 164 | 164 |
|
| 165 |
+// Test for GH#10618 |
|
| 166 |
+func TestContainerApiStartDupVolumeBinds(t *testing.T) {
|
|
| 167 |
+ defer deleteAllContainers() |
|
| 168 |
+ name := "testdups" |
|
| 169 |
+ config := map[string]interface{}{
|
|
| 170 |
+ "Image": "busybox", |
|
| 171 |
+ "Volumes": map[string]struct{}{"/tmp": {}},
|
|
| 172 |
+ } |
|
| 173 |
+ |
|
| 174 |
+ if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
| 175 |
+ t.Fatal(err) |
|
| 176 |
+ } |
|
| 177 |
+ |
|
| 178 |
+ bindPath1, err := ioutil.TempDir("", "test1")
|
|
| 179 |
+ if err != nil {
|
|
| 180 |
+ t.Fatal(err) |
|
| 181 |
+ } |
|
| 182 |
+ defer os.Remove(bindPath1) |
|
| 183 |
+ bindPath2, err := ioutil.TempDir("", "test2")
|
|
| 184 |
+ if err != nil {
|
|
| 185 |
+ t.Fatal(err) |
|
| 186 |
+ } |
|
| 187 |
+ defer os.Remove(bindPath2) |
|
| 188 |
+ |
|
| 189 |
+ config = map[string]interface{}{
|
|
| 190 |
+ "Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
|
| 191 |
+ } |
|
| 192 |
+ if body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
|
|
| 193 |
+ t.Fatal("expected container start to fail when duplicate volume binds to same container path")
|
|
| 194 |
+ } else {
|
|
| 195 |
+ if !strings.Contains(string(body), "Duplicate volume") {
|
|
| 196 |
+ t.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
|
|
| 197 |
+ } |
|
| 198 |
+ } |
|
| 199 |
+ |
|
| 200 |
+ logDone("container REST API - check for duplicate volume binds error on start")
|
|
| 201 |
+} |
|
| 165 | 202 |
func TestContainerApiStartVolumesFrom(t *testing.T) {
|
| 166 | 203 |
defer deleteAllContainers() |
| 167 | 204 |
volName := "voltst" |
| ... | ... |
@@ -495,7 +495,23 @@ func TestVolumesFromGetsProperMode(t *testing.T) {
|
| 495 | 495 |
|
| 496 | 496 |
// Test for GH#10618 |
| 497 | 497 |
func TestRunNoDupVolumes(t *testing.T) {
|
| 498 |
- cmd := exec.Command(dockerBinary, "run", "-v", "/etc:/someplace", "-v", "/usr/lib:/someplace", "busybox", "echo", "hi") |
|
| 498 |
+ |
|
| 499 |
+ bindPath1, err := ioutil.TempDir("", "test1")
|
|
| 500 |
+ if err != nil {
|
|
| 501 |
+ t.Fatal(err) |
|
| 502 |
+ } |
|
| 503 |
+ defer os.Remove(bindPath1) |
|
| 504 |
+ |
|
| 505 |
+ bindPath2, err := ioutil.TempDir("", "test2")
|
|
| 506 |
+ if err != nil {
|
|
| 507 |
+ t.Fatal(err) |
|
| 508 |
+ } |
|
| 509 |
+ defer os.Remove(bindPath2) |
|
| 510 |
+ |
|
| 511 |
+ mountstr1 := bindPath1 + ":/someplace" |
|
| 512 |
+ mountstr2 := bindPath2 + ":/someplace" |
|
| 513 |
+ |
|
| 514 |
+ cmd := exec.Command(dockerBinary, "run", "-v", mountstr1, "-v", mountstr2, "busybox", "true") |
|
| 499 | 515 |
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
| 500 | 516 |
t.Fatal("Expected error about duplicate volume definitions")
|
| 501 | 517 |
} else {
|