فهرست منبع

Add docker tag tests.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
Lei Jitang 10 سال پیش
والد
کامیت
c496f24157
1فایلهای تغییر یافته به همراه40 افزوده شده و 0 حذف شده
  1. 40 0
      integration-cli/docker_cli_tag_test.go

+ 40 - 0
integration-cli/docker_cli_tag_test.go

@@ -3,6 +3,7 @@ package main
 import (
 import (
 	"fmt"
 	"fmt"
 	"os/exec"
 	"os/exec"
+	"strings"
 	"testing"
 	"testing"
 )
 )
 
 
@@ -88,3 +89,42 @@ func TestTagValidPrefixedRepo(t *testing.T) {
 		logDone(logMessage)
 		logDone(logMessage)
 	}
 	}
 }
 }
+
+// tag an image with an existed tag name without -f option should fail
+func TestTagExistedNameWithoutForce(t *testing.T) {
+	if err := pullImageIfNotExist("busybox:latest"); err != nil {
+		t.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
+	}
+
+	tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test")
+	if out, _, err := runCommandWithOutput(tagCmd); err != nil {
+		t.Fatal(out, err)
+	}
+	tagCmd = exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test")
+	out, _, err := runCommandWithOutput(tagCmd)
+	if err == nil || !strings.Contains(out, "Conflict: Tag test is already set to image") {
+		t.Fatal("tag busybox busybox:test should have failed,because busybox:test is existed")
+	}
+	deleteImages("busybox:test")
+
+	logDone("tag - busybox with an existed tag name without -f option --> must fail")
+}
+
+// tag an image with an existed tag name with -f option should work
+func TestTagExistedNameWithForce(t *testing.T) {
+	if err := pullImageIfNotExist("busybox:latest"); err != nil {
+		t.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
+	}
+
+	tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test")
+	if out, _, err := runCommandWithOutput(tagCmd); err != nil {
+		t.Fatal(out, err)
+	}
+	tagCmd = exec.Command(dockerBinary, "tag", "-f", "busybox:latest", "busybox:test")
+	if out, _, err := runCommandWithOutput(tagCmd); err != nil {
+		t.Fatal(out, err)
+	}
+	deleteImages("busybox:test")
+
+	logDone("tag - busybox with an existed tag name with -f option work")
+}