docker_cli_push_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package main
  2. import (
  3. "archive/tar"
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "os/exec"
  8. "strings"
  9. "time"
  10. "github.com/go-check/check"
  11. )
  12. // Pushing an image to a private registry.
  13. func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
  14. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  15. // tag the image to upload it to the private registry
  16. dockerCmd(c, "tag", "busybox", repoName)
  17. // push the image to the registry
  18. dockerCmd(c, "push", repoName)
  19. }
  20. // pushing an image without a prefix should throw an error
  21. func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
  22. if out, _, err := dockerCmdWithError(c, "push", "busybox"); err == nil {
  23. c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
  24. }
  25. }
  26. func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
  27. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  28. expected := "Repository does not exist"
  29. if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
  30. c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
  31. } else if !strings.Contains(out, expected) {
  32. c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
  33. }
  34. }
  35. func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
  36. repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
  37. expected := "does not exist"
  38. if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
  39. c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
  40. } else if !strings.Contains(out, expected) {
  41. c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
  42. }
  43. }
  44. func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
  45. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  46. repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
  47. repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
  48. // tag the image and upload it to the private registry
  49. dockerCmd(c, "tag", "busybox", repoTag1)
  50. dockerCmd(c, "tag", "busybox", repoTag2)
  51. dockerCmd(c, "push", repoName)
  52. }
  53. func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
  54. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  55. // tag the image and upload it to the private registry
  56. dockerCmd(c, "tag", "busybox", repoName)
  57. pushCmd := exec.Command(dockerBinary, "push", repoName)
  58. if err := pushCmd.Start(); err != nil {
  59. c.Fatalf("Failed to start pushing to private registry: %v", err)
  60. }
  61. // Interrupt push (yes, we have no idea at what point it will get killed).
  62. time.Sleep(200 * time.Millisecond)
  63. if err := pushCmd.Process.Kill(); err != nil {
  64. c.Fatalf("Failed to kill push process: %v", err)
  65. }
  66. if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
  67. str := string(out)
  68. if !strings.Contains(str, "already in progress") {
  69. c.Fatalf("Push should be continued on daemon side, but seems ok: %v, %s", err, out)
  70. }
  71. }
  72. // now wait until all this pushes will complete
  73. // if it failed with timeout - there would be some error,
  74. // so no logic about it here
  75. for exec.Command(dockerBinary, "push", repoName).Run() != nil {
  76. }
  77. }
  78. func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
  79. repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
  80. emptyTarball, err := ioutil.TempFile("", "empty_tarball")
  81. if err != nil {
  82. c.Fatalf("Unable to create test file: %v", err)
  83. }
  84. tw := tar.NewWriter(emptyTarball)
  85. err = tw.Close()
  86. if err != nil {
  87. c.Fatalf("Error creating empty tarball: %v", err)
  88. }
  89. freader, err := os.Open(emptyTarball.Name())
  90. if err != nil {
  91. c.Fatalf("Could not open test tarball: %v", err)
  92. }
  93. importCmd := exec.Command(dockerBinary, "import", "-", repoName)
  94. importCmd.Stdin = freader
  95. out, _, err := runCommandWithOutput(importCmd)
  96. if err != nil {
  97. c.Errorf("import failed with errors: %v, output: %q", err, out)
  98. }
  99. // Now verify we can push it
  100. if out, _, err := dockerCmdWithError(c, "push", repoName); err != nil {
  101. c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
  102. }
  103. }