Add some push test coverage
Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
parent
f138f7bd50
commit
dbec2317e5
|
@ -3,30 +3,28 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// these tests need a freshly started empty private docker registry
|
|
||||||
|
|
||||||
// pulling an image from the central registry should work
|
// pulling an image from the central registry should work
|
||||||
func TestPushBusyboxImage(t *testing.T) {
|
func TestPushBusyboxImage(t *testing.T) {
|
||||||
reg, err := newTestRegistryV2(t)
|
defer setupRegistry(t)()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||||
}
|
|
||||||
defer reg.Close()
|
|
||||||
repoName := fmt.Sprintf("%v/dockercli/busybox", reg.URL)
|
|
||||||
// tag the image to upload it tot he private registry
|
// tag the image to upload it tot he private registry
|
||||||
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
|
||||||
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||||
t.Fatalf("image tagging failed: %s, %v", out, err)
|
t.Fatalf("image tagging failed: %s, %v", out, err)
|
||||||
}
|
}
|
||||||
defer deleteImages(repoName)
|
defer deleteImages(repoName)
|
||||||
|
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
||||||
t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
t.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
||||||
}
|
}
|
||||||
logDone("push - push busybox to private registry")
|
logDone("push - busybox to private registry")
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushing an image without a prefix should throw an error
|
// pushing an image without a prefix should throw an error
|
||||||
|
@ -35,5 +33,50 @@ func TestPushUnprefixedRepo(t *testing.T) {
|
||||||
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
||||||
t.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
|
t.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
|
||||||
}
|
}
|
||||||
logDone("push - push unprefixed busybox repo --> must fail")
|
logDone("push - unprefixed busybox repo must fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPushUntagged(t *testing.T) {
|
||||||
|
defer setupRegistry(t)()
|
||||||
|
|
||||||
|
repoName := fmt.Sprintf("%v/dockercli/busybox", 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 - untagged image")
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -864,3 +864,11 @@ func readContainerFile(containerId, filename string) ([]byte, error) {
|
||||||
|
|
||||||
return content, nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupRegistry(t *testing.T) func() {
|
||||||
|
reg, err := newTestRegistryV2(t)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return func() { reg.Close() }
|
||||||
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
const v2binary = "registry-v2"
|
const v2binary = "registry-v2"
|
||||||
|
|
||||||
type testRegistryV2 struct {
|
type testRegistryV2 struct {
|
||||||
URL string
|
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
dir string
|
dir string
|
||||||
}
|
}
|
||||||
|
@ -24,7 +23,7 @@ storage:
|
||||||
filesystem:
|
filesystem:
|
||||||
rootdirectory: %s
|
rootdirectory: %s
|
||||||
http:
|
http:
|
||||||
addr: :%s`
|
addr: %s`
|
||||||
tmp, err := ioutil.TempDir("", "registry-test-")
|
tmp, err := ioutil.TempDir("", "registry-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -34,7 +33,7 @@ http:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(config, template, tmp, "5000"); err != nil {
|
if _, err := fmt.Fprintf(config, template, tmp, privateRegistryURL); err != nil {
|
||||||
os.RemoveAll(tmp)
|
os.RemoveAll(tmp)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -50,7 +49,6 @@ http:
|
||||||
return &testRegistryV2{
|
return &testRegistryV2{
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
dir: tmp,
|
dir: tmp,
|
||||||
URL: "localhost:5000",
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue