Browse code

Merge pull request #10421 from noironetworks/10388-Specifying_confliting_options

Specifying -a and -d to docker run should throw an error

Michael Crosby authored on 2015/02/07 07:58:08
Showing 2 changed files
... ...
@@ -2235,7 +2235,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
2235 2235
 			return err
2236 2236
 		}
2237 2237
 	} else {
2238
-		if fl := cmd.Lookup("attach"); fl != nil {
2238
+		if fl := cmd.Lookup("-attach"); fl != nil {
2239 2239
 			flAttach = fl.Value.(*opts.ListOpts)
2240 2240
 			if flAttach.Len() != 0 {
2241 2241
 				return ErrConflictAttachDetach
... ...
@@ -1753,6 +1753,23 @@ func TestRunAttachStdOutAndErrTTYMode(t *testing.T) {
1753 1753
 	logDone("run - Attach stderr and stdout with -t")
1754 1754
 }
1755 1755
 
1756
+// Test for #10388 - this will run the same test as TestRunAttachStdOutAndErrTTYMode
1757
+// but using --attach instead of -a to make sure we read the flag correctly
1758
+func TestRunAttachWithDettach(t *testing.T) {
1759
+	defer deleteAllContainers()
1760
+
1761
+	cmd := exec.Command(dockerBinary, "run", "-d", "--attach", "stdout", "busybox", "true")
1762
+
1763
+	_, stderr, _, err := runCommandWithStdoutStderr(cmd)
1764
+	if err == nil {
1765
+		t.Fatalf("Container should have exited with error code different than 0", err)
1766
+	} else if !strings.Contains(stderr, "Conflicting options: -a and -d") {
1767
+		t.Fatalf("Should have been returned an error with conflicting options -a and -d")
1768
+	}
1769
+
1770
+	logDone("run - Attach stdout with -d")
1771
+}
1772
+
1756 1773
 func TestRunState(t *testing.T) {
1757 1774
 	defer deleteAllContainers()
1758 1775
 	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")