github.com/microsoft/docker@v1.5.0-rc2/integration-cli/docker_cli_push_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "os/exec" 8 "strings" 9 "testing" 10 "time" 11 12 "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" 13 ) 14 15 // pulling an image from the central registry should work 16 func TestPushBusyboxImage(t *testing.T) { 17 defer setupRegistry(t)() 18 19 repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) 20 // tag the image to upload it tot he private registry 21 tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName) 22 if out, _, err := runCommandWithOutput(tagCmd); err != nil { 23 t.Fatalf("image tagging failed: %s, %v", out, err) 24 } 25 defer deleteImages(repoName) 26 27 pushCmd := exec.Command(dockerBinary, "push", repoName) 28 if out, _, err := runCommandWithOutput(pushCmd); err != nil { 29 t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err) 30 } 31 logDone("push - busybox to private registry") 32 } 33 34 // pushing an image without a prefix should throw an error 35 func TestPushUnprefixedRepo(t *testing.T) { 36 pushCmd := exec.Command(dockerBinary, "push", "busybox") 37 if out, _, err := runCommandWithOutput(pushCmd); err == nil { 38 t.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out) 39 } 40 logDone("push - unprefixed busybox repo must fail") 41 } 42 43 func TestPushUntagged(t *testing.T) { 44 defer setupRegistry(t)() 45 46 repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) 47 48 expected := "does not exist" 49 pushCmd := exec.Command(dockerBinary, "push", repoName) 50 if out, _, err := runCommandWithOutput(pushCmd); err == nil { 51 t.Fatalf("pushing the image to the private registry should have failed: outuput %q", out) 52 } else if !strings.Contains(out, expected) { 53 t.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out) 54 } 55 logDone("push - untagged image") 56 } 57 58 func TestPushInterrupt(t *testing.T) { 59 defer setupRegistry(t)() 60 61 repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) 62 // tag the image to upload it tot he private registry 63 tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName) 64 if out, _, err := runCommandWithOutput(tagCmd); err != nil { 65 t.Fatalf("image tagging failed: %s, %v", out, err) 66 } 67 defer deleteImages(repoName) 68 69 pushCmd := exec.Command(dockerBinary, "push", repoName) 70 if err := pushCmd.Start(); err != nil { 71 t.Fatalf("Failed to start pushing to private registry: %v", err) 72 } 73 74 // Interrupt push (yes, we have no idea at what point it will get killed). 75 time.Sleep(200 * time.Millisecond) 76 if err := pushCmd.Process.Kill(); err != nil { 77 t.Fatalf("Failed to kill push process: %v", err) 78 } 79 // Try agin 80 pushCmd = exec.Command(dockerBinary, "push", repoName) 81 if err := pushCmd.Start(); err != nil { 82 t.Fatalf("Failed to start pushing to private registry: %v", err) 83 } 84 85 logDone("push - interrupted") 86 } 87 88 func TestPushEmptyLayer(t *testing.T) { 89 defer setupRegistry(t)() 90 repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL) 91 emptyTarball, err := ioutil.TempFile("", "empty_tarball") 92 if err != nil { 93 t.Fatalf("Unable to create test file: %v", err) 94 } 95 tw := tar.NewWriter(emptyTarball) 96 err = tw.Close() 97 if err != nil { 98 t.Fatalf("Error creating empty tarball: %v", err) 99 } 100 freader, err := os.Open(emptyTarball.Name()) 101 if err != nil { 102 t.Fatalf("Could not open test tarball: %v", err) 103 } 104 105 importCmd := exec.Command(dockerBinary, "import", "-", repoName) 106 importCmd.Stdin = freader 107 out, _, err := runCommandWithOutput(importCmd) 108 if err != nil { 109 t.Errorf("import failed with errors: %v, output: %q", err, out) 110 } 111 112 // Now verify we can push it 113 pushCmd := exec.Command(dockerBinary, "push", repoName) 114 if out, _, err := runCommandWithOutput(pushCmd); err != nil { 115 t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err) 116 } 117 logDone("push - empty layer config to private registry") 118 }