docker_cli_pull_test.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/go-check/check"
  6. )
  7. // See issue docker/docker#8141
  8. func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
  9. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  10. repos := []string{}
  11. for _, tag := range []string{"recent", "fresh"} {
  12. repos = append(repos, fmt.Sprintf("%v:%v", repoName, tag))
  13. }
  14. // Tag and push the same image multiple times.
  15. for _, repo := range repos {
  16. dockerCmd(c, "tag", "busybox", repo)
  17. dockerCmd(c, "push", repo)
  18. }
  19. // Clear local images store.
  20. args := append([]string{"rmi"}, repos...)
  21. dockerCmd(c, args...)
  22. // Pull a single tag and verify it doesn't bring down all aliases.
  23. dockerCmd(c, "pull", repos[0])
  24. dockerCmd(c, "inspect", repos[0])
  25. for _, repo := range repos[1:] {
  26. if _, _, err := dockerCmdWithError(c, "inspect", repo); err == nil {
  27. c.Fatalf("Image %v shouldn't have been pulled down", repo)
  28. }
  29. }
  30. }
  31. // pulling library/hello-world should show verified message
  32. func (s *DockerSuite) TestPullVerified(c *check.C) {
  33. c.Skip("Skipping hub dependent test")
  34. // Image must be pulled from central repository to get verified message
  35. // unless keychain is manually updated to contain the daemon's sign key.
  36. verifiedName := "hello-world"
  37. // pull it
  38. expected := "The image you are pulling has been verified"
  39. if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || !strings.Contains(out, expected) {
  40. if err != nil || exitCode != 0 {
  41. c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
  42. }
  43. c.Fatalf("pulling a verified image failed. expected: %s\ngot: %s, %v", expected, out, err)
  44. }
  45. // pull it again
  46. if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || strings.Contains(out, expected) {
  47. if err != nil || exitCode != 0 {
  48. c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
  49. }
  50. c.Fatalf("pulling a verified image failed. unexpected verify message\ngot: %s, %v", out, err)
  51. }
  52. }
  53. // pulling an image from the central registry should work
  54. func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
  55. testRequires(c, Network)
  56. dockerCmd(c, "pull", "hello-world")
  57. }
  58. // pulling a non-existing image from the central registry should return a non-zero exit code
  59. func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
  60. testRequires(c, Network)
  61. name := "sadfsadfasdf"
  62. out, _, err := dockerCmdWithError(c, "pull", name)
  63. if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) {
  64. c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
  65. }
  66. }
  67. // pulling an image from the central registry using official names should work
  68. // ensure all pulls result in the same image
  69. func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
  70. testRequires(c, Network)
  71. names := []string{
  72. "docker.io/hello-world",
  73. "index.docker.io/hello-world",
  74. "library/hello-world",
  75. "docker.io/library/hello-world",
  76. "index.docker.io/library/hello-world",
  77. }
  78. for _, name := range names {
  79. out, exitCode, err := dockerCmdWithError(c, "pull", name)
  80. if err != nil || exitCode != 0 {
  81. c.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
  82. continue
  83. }
  84. // ensure we don't have multiple image names.
  85. out, _ = dockerCmd(c, "images")
  86. if strings.Contains(out, name) {
  87. c.Errorf("images should not have listed '%s'", name)
  88. }
  89. }
  90. }
  91. func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
  92. testRequires(c, Network)
  93. out, exitCode, err := dockerCmdWithError(c, "pull", "scratch")
  94. if err == nil {
  95. c.Fatal("expected pull of scratch to fail, but it didn't")
  96. }
  97. if exitCode != 1 {
  98. c.Fatalf("pulling scratch expected exit code 1, got %d", exitCode)
  99. }
  100. if strings.Contains(out, "Pulling repository scratch") {
  101. c.Fatalf("pulling scratch should not have begun: %s", out)
  102. }
  103. if !strings.Contains(out, "'scratch' is a reserved name") {
  104. c.Fatalf("unexpected output pulling scratch: %s", out)
  105. }
  106. }
  107. // pulling an image with --all-tags=true
  108. func (s *DockerSuite) TestPullImageWithAllTagFromCentralRegistry(c *check.C) {
  109. testRequires(c, Network)
  110. dockerCmd(c, "pull", "busybox")
  111. outImageCmd, _ := dockerCmd(c, "images", "busybox")
  112. dockerCmd(c, "pull", "--all-tags=true", "busybox")
  113. outImageAllTagCmd, _ := dockerCmd(c, "images", "busybox")
  114. if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
  115. c.Fatalf("Pulling with all tags should get more images")
  116. }
  117. // FIXME has probably no effect (tags already pushed)
  118. dockerCmd(c, "pull", "-a", "busybox")
  119. outImageAllTagCmd, _ = dockerCmd(c, "images", "busybox")
  120. if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
  121. c.Fatalf("Pulling with all tags should get more images")
  122. }
  123. }