2018-02-05 21:05:59 +00:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
2018-02-01 16:37:14 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-05-04 21:15:00 +00:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2018-02-09 18:37:55 +00:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2019-08-29 20:52:40 +00:00
|
|
|
req "github.com/docker/docker/testutil/request"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/poll"
|
|
|
|
"gotest.tools/v3/skip"
|
2018-02-01 16:37:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestResize(t *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := setupTest(t)
|
2023-08-11 11:45:45 +00:00
|
|
|
apiClient := testEnv.APIClient()
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
cID := container.Run(ctx, t, apiClient, container.WithTty(true))
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
|
2018-02-01 16:37:14 +00:00
|
|
|
Height: 40,
|
|
|
|
Width: 40,
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2018-02-01 16:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestResizeWithInvalidSize(t *testing.T) {
|
2018-05-04 21:15:00 +00:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.32"), "broken in earlier versions")
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := setupTest(t)
|
2023-08-11 11:45:45 +00:00
|
|
|
apiClient := testEnv.APIClient()
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
cID := container.Run(ctx, t, apiClient)
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
2018-02-01 16:37:14 +00:00
|
|
|
|
|
|
|
endpoint := "/containers/" + cID + "/resize?h=foo&w=bar"
|
2023-07-14 18:02:38 +00:00
|
|
|
res, _, err := req.Post(ctx, endpoint)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode))
|
2018-02-01 16:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestResizeWhenContainerNotStarted(t *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := setupTest(t)
|
2023-08-11 11:45:45 +00:00
|
|
|
apiClient := testEnv.APIClient()
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
cID := container.Run(ctx, t, apiClient, container.WithCmd("echo"))
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "exited"), poll.WithDelay(100*time.Millisecond))
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-08-11 11:45:45 +00:00
|
|
|
err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
|
2018-02-01 16:37:14 +00:00
|
|
|
Height: 40,
|
|
|
|
Width: 40,
|
|
|
|
})
|
2018-05-20 22:06:50 +00:00
|
|
|
assert.Check(t, is.ErrorContains(err, "is not running"))
|
2018-02-01 16:37:14 +00:00
|
|
|
}
|