浏览代码

Test pulling image with aliases

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
Arnaud Porterie 10 年之前
父节点
当前提交
92d5eafe03
共有 1 个文件被更改,包括 45 次插入1 次删除
  1. 45 1
      integration-cli/docker_cli_pull_test.go

+ 45 - 1
integration-cli/docker_cli_pull_test.go

@@ -1,12 +1,56 @@
 package main
 package main
 
 
 import (
 import (
+	"fmt"
 	"os/exec"
 	"os/exec"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
 )
 )
 
 
-// FIXME: we need a test for pulling all aliases for an image (issue #8141)
+// See issue docker/docker#8141
+func TestPullImageWithAliases(t *testing.T) {
+	defer setupRegistry(t)()
+
+	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
+	defer deleteImages(repoName)
+
+	repos := []string{}
+	for _, tag := range []string{"recent", "fresh"} {
+		repos = append(repos, fmt.Sprintf("%v:%v", repoName, tag))
+	}
+
+	// Tag and push the same image multiple times.
+	for _, repo := range repos {
+		if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil {
+			t.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out)
+		}
+		if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil {
+			t.Fatalf("Failed to push image %v: error %v, output %q", err, string(out))
+		}
+	}
+
+	// Clear local images store.
+	args := append([]string{"rmi"}, repos...)
+	if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil {
+		t.Fatalf("Failed to clean images: error %v, output %q", err, string(out))
+	}
+
+	// Pull a single tag and verify it doesn't bring down all aliases.
+	pullCmd := exec.Command(dockerBinary, "pull", repos[0])
+	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
+		t.Fatalf("Failed to pull %v: error %v, output %q", repoName, err, out)
+	}
+	if err := exec.Command(dockerBinary, "inspect", repos[0]).Run(); err != nil {
+		t.Fatalf("Image %v was not pulled down", repos[0])
+	}
+	for _, repo := range repos[1:] {
+		if err := exec.Command(dockerBinary, "inspect", repo).Run(); err == nil {
+			t.Fatalf("Image %v shouldn't have been pulled down", repo)
+		}
+	}
+
+	logDone("pull - image with aliases")
+}
 
 
 // pulling an image from the central registry should work
 // pulling an image from the central registry should work
 func TestPullImageFromCentralRegistry(t *testing.T) {
 func TestPullImageFromCentralRegistry(t *testing.T) {