github.com/powellquiring/docker@v1.6.0-rc1/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 defer deleteImages(repo) 28 if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil { 29 t.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out)) 30 } 31 } 32 33 // Clear local images store. 34 args := append([]string{"rmi"}, repos...) 35 if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil { 36 t.Fatalf("Failed to clean images: error %v, output %q", err, string(out)) 37 } 38 39 // Pull a single tag and verify it doesn't bring down all aliases. 40 pullCmd := exec.Command(dockerBinary, "pull", repos[0]) 41 if out, _, err := runCommandWithOutput(pullCmd); err != nil { 42 t.Fatalf("Failed to pull %v: error %v, output %q", repoName, err, out) 43 } 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 library/hello-world should show verified message 57 func TestPullVerified(t *testing.T) { 58 // Image must be pulled from central repository to get verified message 59 // unless keychain is manually updated to contain the daemon's sign key. 60 61 verifiedName := "hello-world" 62 defer deleteImages(verifiedName) 63 64 // pull it 65 expected := "The image you are pulling has been verified" 66 pullCmd := exec.Command(dockerBinary, "pull", verifiedName) 67 if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || !strings.Contains(out, expected) { 68 if err != nil || exitCode != 0 { 69 t.Skipf("pulling the '%s' image from the registry has failed: %s", verifiedName, err) 70 } 71 t.Fatalf("pulling a verified image failed. expected: %s\ngot: %s, %v", expected, out, err) 72 } 73 74 // pull it again 75 pullCmd = exec.Command(dockerBinary, "pull", verifiedName) 76 if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || strings.Contains(out, expected) { 77 if err != nil || exitCode != 0 { 78 t.Skipf("pulling the '%s' image from the registry has failed: %s", verifiedName, err) 79 } 80 t.Fatalf("pulling a verified image failed. unexpected verify message\ngot: %s, %v", out, err) 81 } 82 83 logDone("pull - pull verified") 84 } 85 86 // pulling an image from the central registry should work 87 func TestPullImageFromCentralRegistry(t *testing.T) { 88 defer deleteImages("hello-world") 89 90 pullCmd := exec.Command(dockerBinary, "pull", "hello-world") 91 if out, _, err := runCommandWithOutput(pullCmd); err != nil { 92 t.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err) 93 } 94 logDone("pull - pull hello-world") 95 } 96 97 // pulling a non-existing image from the central registry should return a non-zero exit code 98 func TestPullNonExistingImage(t *testing.T) { 99 pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234") 100 if out, _, err := runCommandWithOutput(pullCmd); err == nil { 101 t.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out) 102 } 103 logDone("pull - pull fooblahblah1234 (non-existing image)") 104 } 105 106 // pulling an image from the central registry using official names should work 107 // ensure all pulls result in the same image 108 func TestPullImageOfficialNames(t *testing.T) { 109 names := []string{ 110 "docker.io/hello-world", 111 "index.docker.io/hello-world", 112 "library/hello-world", 113 "docker.io/library/hello-world", 114 "index.docker.io/library/hello-world", 115 } 116 for _, name := range names { 117 pullCmd := exec.Command(dockerBinary, "pull", name) 118 out, exitCode, err := runCommandWithOutput(pullCmd) 119 if err != nil || exitCode != 0 { 120 t.Errorf("pulling the '%s' image from the registry has failed: %s", name, err) 121 continue 122 } 123 124 // ensure we don't have multiple image names. 125 imagesCmd := exec.Command(dockerBinary, "images") 126 out, _, err = runCommandWithOutput(imagesCmd) 127 if err != nil { 128 t.Errorf("listing images failed with errors: %v", err) 129 } else if strings.Contains(out, name) { 130 t.Errorf("images should not have listed '%s'", name) 131 } 132 } 133 logDone("pull - pull official names") 134 }