github.com/dougm/docker@v1.5.0/integration-cli/docker_api_resize_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func TestResizeApiResponse(t *testing.T) {
    10  	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
    11  	out, _, err := runCommandWithOutput(runCmd)
    12  	if err != nil {
    13  		t.Fatalf(out, err)
    14  	}
    15  	defer deleteAllContainers()
    16  	cleanedContainerID := stripTrailingCharacters(out)
    17  
    18  	endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
    19  	_, err = sockRequest("POST", endpoint, nil)
    20  	if err != nil {
    21  		t.Fatalf("resize Request failed %v", err)
    22  	}
    23  
    24  	logDone("container resize - when started")
    25  }
    26  
    27  func TestResizeApiResponseWhenContainerNotStarted(t *testing.T) {
    28  	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
    29  	out, _, err := runCommandWithOutput(runCmd)
    30  	if err != nil {
    31  		t.Fatalf(out, err)
    32  	}
    33  	defer deleteAllContainers()
    34  	cleanedContainerID := stripTrailingCharacters(out)
    35  
    36  	// make sure the exited cintainer is not running
    37  	runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
    38  	out, _, err = runCommandWithOutput(runCmd)
    39  	if err != nil {
    40  		t.Fatalf(out, err)
    41  	}
    42  
    43  	endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
    44  	body, err := sockRequest("POST", endpoint, nil)
    45  	if err == nil {
    46  		t.Fatalf("resize should fail when container is not started")
    47  	}
    48  	if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
    49  		t.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
    50  	}
    51  
    52  	logDone("container resize - when not started should not resize")
    53  }