Clean up dup. volume test and add API test for the same
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)
This commit is contained in:
parent
a98355561d
commit
35d4825838
2 changed files with 54 additions and 1 deletions
|
@ -162,6 +162,43 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
|
||||||
logDone("container REST API - check volume binds on start")
|
logDone("container REST API - check volume binds on start")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test for GH#10618
|
||||||
|
func TestContainerApiStartDupVolumeBinds(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
name := "testdups"
|
||||||
|
config := map[string]interface{}{
|
||||||
|
"Image": "busybox",
|
||||||
|
"Volumes": map[string]struct{}{"/tmp": {}},
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bindPath1, err := ioutil.TempDir("", "test1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(bindPath1)
|
||||||
|
bindPath2, err := ioutil.TempDir("", "test2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(bindPath2)
|
||||||
|
|
||||||
|
config = map[string]interface{}{
|
||||||
|
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
||||||
|
}
|
||||||
|
if body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
|
||||||
|
t.Fatal("expected container start to fail when duplicate volume binds to same container path")
|
||||||
|
} else {
|
||||||
|
if !strings.Contains(string(body), "Duplicate volume") {
|
||||||
|
t.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("container REST API - check for duplicate volume binds error on start")
|
||||||
|
}
|
||||||
func TestContainerApiStartVolumesFrom(t *testing.T) {
|
func TestContainerApiStartVolumesFrom(t *testing.T) {
|
||||||
defer deleteAllContainers()
|
defer deleteAllContainers()
|
||||||
volName := "voltst"
|
volName := "voltst"
|
||||||
|
|
|
@ -495,7 +495,23 @@ func TestVolumesFromGetsProperMode(t *testing.T) {
|
||||||
|
|
||||||
// Test for GH#10618
|
// Test for GH#10618
|
||||||
func TestRunNoDupVolumes(t *testing.T) {
|
func TestRunNoDupVolumes(t *testing.T) {
|
||||||
cmd := exec.Command(dockerBinary, "run", "-v", "/etc:/someplace", "-v", "/usr/lib:/someplace", "busybox", "echo", "hi")
|
|
||||||
|
bindPath1, err := ioutil.TempDir("", "test1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(bindPath1)
|
||||||
|
|
||||||
|
bindPath2, err := ioutil.TempDir("", "test2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(bindPath2)
|
||||||
|
|
||||||
|
mountstr1 := bindPath1 + ":/someplace"
|
||||||
|
mountstr2 := bindPath2 + ":/someplace"
|
||||||
|
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "-v", mountstr1, "-v", mountstr2, "busybox", "true")
|
||||||
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
||||||
t.Fatal("Expected error about duplicate volume definitions")
|
t.Fatal("Expected error about duplicate volume definitions")
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue