github.com/pritambaral/docker@v1.4.2-0.20150120174542-b2fe1b3dd952/integration-cli/docker_cli_push_test.go (about)

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