github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/container/resize_test.go (about)

     1  package container // import "github.com/docker/docker/integration/container"
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/docker/docker/api/types"
    10  	"github.com/docker/docker/api/types/versions"
    11  	"github.com/docker/docker/integration/internal/container"
    12  	req "github.com/docker/docker/testutil/request"
    13  	"gotest.tools/v3/assert"
    14  	is "gotest.tools/v3/assert/cmp"
    15  	"gotest.tools/v3/poll"
    16  	"gotest.tools/v3/skip"
    17  )
    18  
    19  func TestResize(t *testing.T) {
    20  	defer setupTest(t)()
    21  	client := testEnv.APIClient()
    22  	ctx := context.Background()
    23  
    24  	cID := container.Run(ctx, t, client, container.WithTty(true))
    25  
    26  	poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
    27  
    28  	err := client.ContainerResize(ctx, cID, types.ResizeOptions{
    29  		Height: 40,
    30  		Width:  40,
    31  	})
    32  	assert.NilError(t, err)
    33  }
    34  
    35  func TestResizeWithInvalidSize(t *testing.T) {
    36  	skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.32"), "broken in earlier versions")
    37  	defer setupTest(t)()
    38  	client := testEnv.APIClient()
    39  	ctx := context.Background()
    40  
    41  	cID := container.Run(ctx, t, client)
    42  
    43  	poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
    44  
    45  	endpoint := "/containers/" + cID + "/resize?h=foo&w=bar"
    46  	res, _, err := req.Post(endpoint)
    47  	assert.NilError(t, err)
    48  	assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode))
    49  }
    50  
    51  func TestResizeWhenContainerNotStarted(t *testing.T) {
    52  	defer setupTest(t)()
    53  	client := testEnv.APIClient()
    54  	ctx := context.Background()
    55  
    56  	cID := container.Run(ctx, t, client, container.WithCmd("echo"))
    57  
    58  	poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond))
    59  
    60  	err := client.ContainerResize(ctx, cID, types.ResizeOptions{
    61  		Height: 40,
    62  		Width:  40,
    63  	})
    64  	assert.Check(t, is.ErrorContains(err, "is not running"))
    65  }