github.com/lacework-dev/go-moby@v20.10.12+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) 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 skip.If(t, testEnv.OSType == "windows", "FIXME") 38 defer setupTest(t)() 39 client := testEnv.APIClient() 40 ctx := context.Background() 41 42 cID := container.Run(ctx, t, client) 43 44 poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) 45 46 endpoint := "/containers/" + cID + "/resize?h=foo&w=bar" 47 res, _, err := req.Post(endpoint) 48 assert.NilError(t, err) 49 assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode)) 50 } 51 52 func TestResizeWhenContainerNotStarted(t *testing.T) { 53 defer setupTest(t)() 54 client := testEnv.APIClient() 55 ctx := context.Background() 56 57 cID := container.Run(ctx, t, client, container.WithCmd("echo")) 58 59 poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) 60 61 err := client.ContainerResize(ctx, cID, types.ResizeOptions{ 62 Height: 40, 63 Width: 40, 64 }) 65 assert.Check(t, is.ErrorContains(err, "is not running")) 66 }