Przeglądaj źródła

add test and move one from rm to rmi

Signed-off-by: Victor Vieux <vieux@docker.com>
Victor Vieux 10 lat temu
rodzic
commit
c68e6b15a5

+ 4 - 20
integration-cli/docker_cli_rm_test.go

@@ -110,28 +110,12 @@ func TestRmContainerOrphaning(t *testing.T) {
 	logDone("rm - container orphaning")
 }
 
-func TestRmTagWithExistingContainers(t *testing.T) {
-	container := "test-delete-tag"
-	newtag := "busybox:newtag"
-	bb := "busybox:latest"
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", bb, newtag)); err != nil {
-		t.Fatalf("Could not tag busybox: %v: %s", err, out)
+func TestRmInvalidContainer(t *testing.T) {
+	if _, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rm", "unknown")); err == nil {
+		t.Fatal("Expected error on rm unknown container, got none")
 	}
-	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", container, bb, "/bin/true")); err != nil {
-		t.Fatalf("Could not run busybox: %v: %s", err, out)
-	}
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rmi", newtag))
-	if err != nil {
-		t.Fatalf("Could not remove tag %s: %v: %s", newtag, err, out)
-	}
-	if d := strings.Count(out, "Untagged: "); d != 1 {
-		t.Fatalf("Expected 1 untagged entry got %d: %q", d, out)
-	}
-
-	deleteAllContainers()
-
-	logDone("rm - delete tag with existing containers")
 
+	logDone("rm - delete unknown container")
 }
 
 func createRunningContainer(t *testing.T, name string) {

+ 23 - 0
integration-cli/docker_cli_rmi_test.go

@@ -75,3 +75,26 @@ func TestRmiTag(t *testing.T) {
 	}
 	logDone("tag,rmi- tagging the same images multiple times then removing tags")
 }
+
+func TestRmiTagWithExistingContainers(t *testing.T) {
+	container := "test-delete-tag"
+	newtag := "busybox:newtag"
+	bb := "busybox:latest"
+	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", bb, newtag)); err != nil {
+		t.Fatalf("Could not tag busybox: %v: %s", err, out)
+	}
+	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", container, bb, "/bin/true")); err != nil {
+		t.Fatalf("Could not run busybox: %v: %s", err, out)
+	}
+	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rmi", newtag))
+	if err != nil {
+		t.Fatalf("Could not remove tag %s: %v: %s", newtag, err, out)
+	}
+	if d := strings.Count(out, "Untagged: "); d != 1 {
+		t.Fatalf("Expected 1 untagged entry got %d: %q", d, out)
+	}
+
+	deleteAllContainers()
+
+	logDone("rmi - delete tag with existing containers")
+}