docker_cli_push_test.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "strings"
  6. "testing"
  7. "time"
  8. )
  9. // pulling an image from the central registry should work
  10. func TestPushBusyboxImage(t *testing.T) {
  11. defer setupRegistry(t)()
  12. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  13. // tag the image to upload it tot he private registry
  14. tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
  15. if out, _, err := runCommandWithOutput(tagCmd); err != nil {
  16. t.Fatalf("image tagging failed: %s, %v", out, err)
  17. }
  18. defer deleteImages(repoName)
  19. pushCmd := exec.Command(dockerBinary, "push", repoName)
  20. if out, _, err := runCommandWithOutput(pushCmd); err != nil {
  21. t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
  22. }
  23. logDone("push - busybox to private registry")
  24. }
  25. // pushing an image without a prefix should throw an error
  26. func TestPushUnprefixedRepo(t *testing.T) {
  27. pushCmd := exec.Command(dockerBinary, "push", "busybox")
  28. if out, _, err := runCommandWithOutput(pushCmd); err == nil {
  29. t.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
  30. }
  31. logDone("push - unprefixed busybox repo must fail")
  32. }
  33. func TestPushUntagged(t *testing.T) {
  34. defer setupRegistry(t)()
  35. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  36. expected := "does not exist"
  37. pushCmd := exec.Command(dockerBinary, "push", repoName)
  38. if out, _, err := runCommandWithOutput(pushCmd); err == nil {
  39. t.Fatalf("pushing the image to the private registry should have failed: outuput %q", out)
  40. } else if !strings.Contains(out, expected) {
  41. t.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
  42. }
  43. logDone("push - untagged image")
  44. }
  45. func TestPushInterrupt(t *testing.T) {
  46. defer setupRegistry(t)()
  47. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  48. // tag the image to upload it tot he private registry
  49. tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
  50. if out, _, err := runCommandWithOutput(tagCmd); err != nil {
  51. t.Fatalf("image tagging failed: %s, %v", out, err)
  52. }
  53. defer deleteImages(repoName)
  54. pushCmd := exec.Command(dockerBinary, "push", repoName)
  55. if err := pushCmd.Start(); err != nil {
  56. t.Fatalf("Failed to start pushing to private registry: %v", err)
  57. }
  58. // Interrupt push (yes, we have no idea at what point it will get killed).
  59. time.Sleep(200 * time.Millisecond)
  60. if err := pushCmd.Process.Kill(); err != nil {
  61. t.Fatalf("Failed to kill push process: %v", err)
  62. }
  63. // Try agin
  64. pushCmd = exec.Command(dockerBinary, "push", repoName)
  65. if err := pushCmd.Start(); err != nil {
  66. t.Fatalf("Failed to start pushing to private registry: %v", err)
  67. }
  68. logDone("push - interrupted")
  69. }