зеркало из https://github.com/microsoft/docker.git
Add docker tag tests.
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
Родитель
5e6f16e342
Коммит
c496f24157
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -88,3 +89,42 @@ func TestTagValidPrefixedRepo(t *testing.T) {
|
|||
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")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче