integration-cli/docker_cli_pull_test.go
6db32fde
 package main
 
 import (
92d5eafe
 	"fmt"
6db32fde
 	"os/exec"
568f86eb
 	"strings"
dc944ea7
 
 	"github.com/go-check/check"
6db32fde
 )
 
92d5eafe
 // See issue docker/docker#8141
f696b107
 func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
92d5eafe
 	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
 
 	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 {
dc944ea7
 			c.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out)
92d5eafe
 		}
 		if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil {
dc944ea7
 			c.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out))
92d5eafe
 		}
 	}
 
 	// Clear local images store.
 	args := append([]string{"rmi"}, repos...)
 	if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil {
dc944ea7
 		c.Fatalf("Failed to clean images: error %v, output %q", err, string(out))
92d5eafe
 	}
 
 	// 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 {
dc944ea7
 		c.Fatalf("Failed to pull %v: error %v, output %q", repoName, err, out)
92d5eafe
 	}
 	if err := exec.Command(dockerBinary, "inspect", repos[0]).Run(); err != nil {
dc944ea7
 		c.Fatalf("Image %v was not pulled down", repos[0])
92d5eafe
 	}
 	for _, repo := range repos[1:] {
 		if err := exec.Command(dockerBinary, "inspect", repo).Run(); err == nil {
dc944ea7
 			c.Fatalf("Image %v shouldn't have been pulled down", repo)
92d5eafe
 		}
 	}
 }
7d74be16
 
6088df20
 // pulling library/hello-world should show verified message
dc944ea7
 func (s *DockerSuite) TestPullVerified(c *check.C) {
 	c.Skip("Skipping hub dependent test")
9a4fa9c1
 
6088df20
 	// Image must be pulled from central repository to get verified message
 	// unless keychain is manually updated to contain the daemon's sign key.
614e09a8
 
6088df20
 	verifiedName := "hello-world"
614e09a8
 
 	// pull it
 	expected := "The image you are pulling has been verified"
6088df20
 	pullCmd := exec.Command(dockerBinary, "pull", verifiedName)
 	if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || !strings.Contains(out, expected) {
 		if err != nil || exitCode != 0 {
dc944ea7
 			c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
6088df20
 		}
dc944ea7
 		c.Fatalf("pulling a verified image failed. expected: %s\ngot: %s, %v", expected, out, err)
614e09a8
 	}
 
 	// pull it again
6088df20
 	pullCmd = exec.Command(dockerBinary, "pull", verifiedName)
 	if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || strings.Contains(out, expected) {
 		if err != nil || exitCode != 0 {
dc944ea7
 			c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
6088df20
 		}
dc944ea7
 		c.Fatalf("pulling a verified image failed. unexpected verify message\ngot: %s, %v", out, err)
614e09a8
 	}
 
 }
 
6db32fde
 // pulling an image from the central registry should work
dc944ea7
 func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
 	testRequires(c, Network)
5d70a97b
 
89367899
 	pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
eeb00972
 	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
dc944ea7
 		c.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err)
6db32fde
 	}
 }
 
 // pulling a non-existing image from the central registry should return a non-zero exit code
dc944ea7
 func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
7a525c6c
 	testRequires(c, Network)
 
 	name := "sadfsadfasdf"
 	pullCmd := exec.Command(dockerBinary, "pull", name)
 	out, _, err := runCommandWithOutput(pullCmd)
 
 	if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) {
dc944ea7
 		c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
6db32fde
 	}
 }
568f86eb
 
 // pulling an image from the central registry using official names should work
 // ensure all pulls result in the same image
dc944ea7
 func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
 	testRequires(c, Network)
5daa9260
 
568f86eb
 	names := []string{
 		"docker.io/hello-world",
 		"index.docker.io/hello-world",
 		"library/hello-world",
 		"docker.io/library/hello-world",
 		"index.docker.io/library/hello-world",
 	}
 	for _, name := range names {
 		pullCmd := exec.Command(dockerBinary, "pull", name)
 		out, exitCode, err := runCommandWithOutput(pullCmd)
 		if err != nil || exitCode != 0 {
dc944ea7
 			c.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
568f86eb
 			continue
 		}
 
 		// ensure we don't have multiple image names.
 		imagesCmd := exec.Command(dockerBinary, "images")
 		out, _, err = runCommandWithOutput(imagesCmd)
 		if err != nil {
dc944ea7
 			c.Errorf("listing images failed with errors: %v", err)
568f86eb
 		} else if strings.Contains(out, name) {
dc944ea7
 			c.Errorf("images should not have listed '%s'", name)
568f86eb
 		}
 	}
 }
18f46883
 
 func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
 	testRequires(c, Network)
 
 	pullCmd := exec.Command(dockerBinary, "pull", "scratch")
 	out, exitCode, err := runCommandWithOutput(pullCmd)
 	if err == nil {
 		c.Fatal("expected pull of scratch to fail, but it didn't")
 	}
 	if exitCode != 1 {
 		c.Fatalf("pulling scratch expected exit code 1, got %d", exitCode)
 	}
 	if strings.Contains(out, "Pulling repository scratch") {
 		c.Fatalf("pulling scratch should not have begun: %s", out)
 	}
 	if !strings.Contains(out, "'scratch' is a reserved name") {
 		c.Fatalf("unexpected output pulling scratch: %s", out)
 	}
 }