github.com/adxhyt/docker@v1.4.2-0.20150117221845-467b7c821390/integration-cli/docker_cli_pull_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  // FIXME: we need a test for pulling all aliases for an image (issue #8141)
    10  
    11  // pulling an image from the central registry should work
    12  func TestPullImageFromCentralRegistry(t *testing.T) {
    13  	pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
    14  	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
    15  		t.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err)
    16  	}
    17  	logDone("pull - pull hello-world")
    18  }
    19  
    20  // pulling a non-existing image from the central registry should return a non-zero exit code
    21  func TestPullNonExistingImage(t *testing.T) {
    22  	pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234")
    23  	if out, _, err := runCommandWithOutput(pullCmd); err == nil {
    24  		t.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
    25  	}
    26  	logDone("pull - pull fooblahblah1234 (non-existing image)")
    27  }
    28  
    29  // pulling an image from the central registry using official names should work
    30  // ensure all pulls result in the same image
    31  func TestPullImageOfficialNames(t *testing.T) {
    32  	names := []string{
    33  		"docker.io/hello-world",
    34  		"index.docker.io/hello-world",
    35  		"library/hello-world",
    36  		"docker.io/library/hello-world",
    37  		"index.docker.io/library/hello-world",
    38  	}
    39  	for _, name := range names {
    40  		pullCmd := exec.Command(dockerBinary, "pull", name)
    41  		out, exitCode, err := runCommandWithOutput(pullCmd)
    42  		if err != nil || exitCode != 0 {
    43  			t.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
    44  			continue
    45  		}
    46  
    47  		// ensure we don't have multiple image names.
    48  		imagesCmd := exec.Command(dockerBinary, "images")
    49  		out, _, err = runCommandWithOutput(imagesCmd)
    50  		if err != nil {
    51  			t.Errorf("listing images failed with errors: %v", err)
    52  		} else if strings.Contains(out, name) {
    53  			t.Errorf("images should not have listed '%s'", name)
    54  		}
    55  	}
    56  	logDone("pull - pull official names")
    57  }