docker_cli_pull_test.go 1.9 KB

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