github.com/pritambaral/docker@v1.4.2-0.20150120174542-b2fe1b3dd952/integration-cli/docker_cli_pull_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os/exec" 6 "strings" 7 "testing" 8 ) 9 10 // See issue docker/docker#8141 11 func TestPullImageWithAliases(t *testing.T) { 12 defer setupRegistry(t)() 13 14 repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) 15 defer deleteImages(repoName) 16 17 repos := []string{} 18 for _, tag := range []string{"recent", "fresh"} { 19 repos = append(repos, fmt.Sprintf("%v:%v", repoName, tag)) 20 } 21 22 // Tag and push the same image multiple times. 23 for _, repo := range repos { 24 if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil { 25 t.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out) 26 } 27 if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil { 28 t.Fatalf("Failed to push image %v: error %v, output %q", err, string(out)) 29 } 30 } 31 32 // Clear local images store. 33 args := append([]string{"rmi"}, repos...) 34 if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil { 35 t.Fatalf("Failed to clean images: error %v, output %q", err, string(out)) 36 } 37 38 // Pull a single tag and verify it doesn't bring down all aliases. 39 pullCmd := exec.Command(dockerBinary, "pull", repos[0]) 40 if out, _, err := runCommandWithOutput(pullCmd); err != nil { 41 t.Fatalf("Failed to pull %v: error %v, output %q", repoName, err, out) 42 } 43 defer deleteImages(repos[0]) 44 if err := exec.Command(dockerBinary, "inspect", repos[0]).Run(); err != nil { 45 t.Fatalf("Image %v was not pulled down", repos[0]) 46 } 47 for _, repo := range repos[1:] { 48 if err := exec.Command(dockerBinary, "inspect", repo).Run(); err == nil { 49 t.Fatalf("Image %v shouldn't have been pulled down", repo) 50 } 51 } 52 53 logDone("pull - image with aliases") 54 } 55 56 // pulling an image from the central registry should work 57 func TestPullImageFromCentralRegistry(t *testing.T) { 58 pullCmd := exec.Command(dockerBinary, "pull", "hello-world") 59 if out, _, err := runCommandWithOutput(pullCmd); err != nil { 60 t.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err) 61 } 62 logDone("pull - pull hello-world") 63 } 64 65 // pulling a non-existing image from the central registry should return a non-zero exit code 66 func TestPullNonExistingImage(t *testing.T) { 67 pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234") 68 if out, _, err := runCommandWithOutput(pullCmd); err == nil { 69 t.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out) 70 } 71 logDone("pull - pull fooblahblah1234 (non-existing image)") 72 } 73 74 // pulling an image from the central registry using official names should work 75 // ensure all pulls result in the same image 76 func TestPullImageOfficialNames(t *testing.T) { 77 names := []string{ 78 "docker.io/hello-world", 79 "index.docker.io/hello-world", 80 "library/hello-world", 81 "docker.io/library/hello-world", 82 "index.docker.io/library/hello-world", 83 } 84 for _, name := range names { 85 pullCmd := exec.Command(dockerBinary, "pull", name) 86 out, exitCode, err := runCommandWithOutput(pullCmd) 87 if err != nil || exitCode != 0 { 88 t.Errorf("pulling the '%s' image from the registry has failed: %s", name, err) 89 continue 90 } 91 92 // ensure we don't have multiple image names. 93 imagesCmd := exec.Command(dockerBinary, "images") 94 out, _, err = runCommandWithOutput(imagesCmd) 95 if err != nil { 96 t.Errorf("listing images failed with errors: %v", err) 97 } else if strings.Contains(out, name) { 98 t.Errorf("images should not have listed '%s'", name) 99 } 100 } 101 logDone("pull - pull official names") 102 }