github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/container/resize_test.go (about) 1 package container // import "github.com/demonoid81/moby/integration/container" 2 3 import ( 4 "context" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/demonoid81/moby/api/types" 10 "github.com/demonoid81/moby/api/types/versions" 11 "github.com/demonoid81/moby/integration/internal/container" 12 req "github.com/demonoid81/moby/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 skip.If(t, testEnv.OSType == "windows", "FIXME") 21 defer setupTest(t)() 22 client := testEnv.APIClient() 23 ctx := context.Background() 24 25 cID := container.Run(ctx, t, client) 26 27 poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) 28 29 err := client.ContainerResize(ctx, cID, types.ResizeOptions{ 30 Height: 40, 31 Width: 40, 32 }) 33 assert.NilError(t, err) 34 } 35 36 func TestResizeWithInvalidSize(t *testing.T) { 37 skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.32"), "broken in earlier versions") 38 skip.If(t, testEnv.OSType == "windows", "FIXME") 39 defer setupTest(t)() 40 client := testEnv.APIClient() 41 ctx := context.Background() 42 43 cID := container.Run(ctx, t, client) 44 45 poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) 46 47 endpoint := "/containers/" + cID + "/resize?h=foo&w=bar" 48 res, _, err := req.Post(endpoint) 49 assert.NilError(t, err) 50 assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode)) 51 } 52 53 func TestResizeWhenContainerNotStarted(t *testing.T) { 54 defer setupTest(t)() 55 client := testEnv.APIClient() 56 ctx := context.Background() 57 58 cID := container.Run(ctx, t, client, container.WithCmd("echo")) 59 60 poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) 61 62 err := client.ContainerResize(ctx, cID, types.ResizeOptions{ 63 Height: 40, 64 Width: 40, 65 }) 66 assert.Check(t, is.ErrorContains(err, "is not running")) 67 }