2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-01-24 16:08:47 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2014-02-25 11:17:48 -05:00
|
|
|
"os/exec"
|
2015-01-13 13:46:32 -05:00
|
|
|
"strings"
|
2014-02-25 11:17:48 -05:00
|
|
|
"testing"
|
2015-01-13 13:46:32 -05:00
|
|
|
"time"
|
2015-01-24 16:08:47 -05:00
|
|
|
|
|
|
|
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// pulling an image from the central registry should work
|
|
|
|
func TestPushBusyboxImage(t *testing.T) {
|
2015-01-13 13:46:32 -05:00
|
|
|
defer setupRegistry(t)()
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
2015-02-26 21:23:50 -05:00
|
|
|
// tag the image to upload it to the private registry
|
2014-02-25 11:17:48 -05:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
|
2014-10-14 17:02:15 -04:00
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2014-11-05 11:26:22 -05:00
|
|
|
t.Fatalf("image tagging failed: %s, %v", out, err)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2015-01-12 17:30:19 -05:00
|
|
|
defer deleteImages(repoName)
|
2015-01-13 13:46:32 -05:00
|
|
|
|
2014-02-25 11:17:48 -05:00
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
2014-10-14 17:02:15 -04:00
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
2014-11-05 11:26:22 -05:00
|
|
|
t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
2014-10-14 17:02:15 -04:00
|
|
|
}
|
2015-01-13 13:46:32 -05:00
|
|
|
logDone("push - busybox to private registry")
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// pushing an image without a prefix should throw an error
|
|
|
|
func TestPushUnprefixedRepo(t *testing.T) {
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", "busybox")
|
2014-10-14 17:02:15 -04:00
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
2014-11-05 11:26:22 -05:00
|
|
|
t.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2015-02-09 18:01:52 -05:00
|
|
|
logDone("push - unprefixed busybox repo must not pass")
|
2015-01-13 13:46:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPushUntagged(t *testing.T) {
|
|
|
|
defer setupRegistry(t)()
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
2015-03-04 15:05:17 -05:00
|
|
|
expected := "Repository does not exist"
|
2015-01-13 13:46:32 -05:00
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
|
|
|
t.Fatalf("pushing the image to the private registry should have failed: outuput %q", out)
|
|
|
|
} else if !strings.Contains(out, expected) {
|
|
|
|
t.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
|
|
|
}
|
|
|
|
logDone("push - untagged image")
|
|
|
|
}
|
|
|
|
|
2015-01-30 17:20:32 -05:00
|
|
|
func TestPushBadTag(t *testing.T) {
|
|
|
|
defer setupRegistry(t)()
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
|
|
|
|
|
|
|
|
expected := "does not exist"
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
|
|
|
t.Fatalf("pushing the image to the private registry should have failed: outuput %q", out)
|
|
|
|
} else if !strings.Contains(out, expected) {
|
|
|
|
t.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
|
|
|
}
|
|
|
|
logDone("push - image with bad tag")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPushMultipleTags(t *testing.T) {
|
|
|
|
defer setupRegistry(t)()
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
|
|
|
|
repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
|
|
|
|
// tag the image to upload it tot he private registry
|
|
|
|
tagCmd1 := exec.Command(dockerBinary, "tag", "busybox", repoTag1)
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd1); err != nil {
|
|
|
|
t.Fatalf("image tagging failed: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
defer deleteImages(repoTag1)
|
|
|
|
tagCmd2 := exec.Command(dockerBinary, "tag", "busybox", repoTag2)
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd2); err != nil {
|
|
|
|
t.Fatalf("image tagging failed: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
defer deleteImages(repoTag2)
|
|
|
|
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
|
|
|
t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
logDone("push - multiple tags to private registry")
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:46:32 -05:00
|
|
|
func TestPushInterrupt(t *testing.T) {
|
|
|
|
defer setupRegistry(t)()
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
// tag the image to upload it tot he private registry
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
|
|
|
t.Fatalf("image tagging failed: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
defer deleteImages(repoName)
|
|
|
|
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if err := pushCmd.Start(); err != nil {
|
|
|
|
t.Fatalf("Failed to start pushing to private registry: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Interrupt push (yes, we have no idea at what point it will get killed).
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
if err := pushCmd.Process.Kill(); err != nil {
|
|
|
|
t.Fatalf("Failed to kill push process: %v", err)
|
|
|
|
}
|
|
|
|
// Try agin
|
|
|
|
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if err := pushCmd.Start(); err != nil {
|
|
|
|
t.Fatalf("Failed to start pushing to private registry: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("push - interrupted")
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2015-01-24 16:08:47 -05:00
|
|
|
|
|
|
|
func TestPushEmptyLayer(t *testing.T) {
|
|
|
|
defer setupRegistry(t)()
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
|
|
|
|
emptyTarball, err := ioutil.TempFile("", "empty_tarball")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to create test file: %v", err)
|
|
|
|
}
|
|
|
|
tw := tar.NewWriter(emptyTarball)
|
|
|
|
err = tw.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating empty tarball: %v", err)
|
|
|
|
}
|
|
|
|
freader, err := os.Open(emptyTarball.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not open test tarball: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", repoName)
|
|
|
|
importCmd.Stdin = freader
|
|
|
|
out, _, err := runCommandWithOutput(importCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now verify we can push it
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
|
|
|
t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
logDone("push - empty layer config to private registry")
|
|
|
|
}
|