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"
|
|
|
|
|
2023-08-25 18:00:58 +00:00
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
2023-09-07 12:18:43 +00:00
|
|
|
"github.com/docker/docker/errdefs"
|
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"
|
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-09-07 13:35:02 +00:00
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
cID := container.Run(ctx, t, apiClient, container.WithTty(true))
|
2023-08-25 18:00:58 +00:00
|
|
|
err := apiClient.ContainerResize(ctx, cID, containertypes.ResizeOptions{
|
2023-09-07 13:35:02 +00:00
|
|
|
Height: 40,
|
|
|
|
Width: 40,
|
|
|
|
})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
// TODO(thaJeztah): also check if the resize happened
|
|
|
|
//
|
|
|
|
// Note: container inspect shows the initial size that was
|
|
|
|
// set when creating the container. Actual resize happens in
|
|
|
|
// containerd, and currently does not update the container's
|
|
|
|
// config after running (but does send a "resize" event).
|
2018-02-01 16:37:14 +00:00
|
|
|
})
|
|
|
|
|
2023-09-07 13:35:02 +00:00
|
|
|
t.Run("invalid size", func(t *testing.T) {
|
|
|
|
cID := container.Run(ctx, t, apiClient)
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-09-07 13:35:02 +00:00
|
|
|
// Manually creating a request here, as the APIClient would invalidate
|
|
|
|
// these values before they're sent.
|
|
|
|
res, _, err := req.Post(ctx, "/containers/"+cID+"/resize?h=foo&w=bar")
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode))
|
|
|
|
})
|
2018-02-01 16:37:14 +00:00
|
|
|
|
2023-09-07 13:35:02 +00:00
|
|
|
t.Run("invalid state", func(t *testing.T) {
|
|
|
|
cID := container.Create(ctx, t, apiClient, container.WithCmd("echo"))
|
2023-08-25 18:00:58 +00:00
|
|
|
err := apiClient.ContainerResize(ctx, cID, containertypes.ResizeOptions{
|
2023-09-07 13:35:02 +00:00
|
|
|
Height: 40,
|
|
|
|
Width: 40,
|
|
|
|
})
|
|
|
|
assert.Check(t, is.ErrorType(err, errdefs.IsConflict))
|
|
|
|
assert.Check(t, is.ErrorContains(err, "is not running"))
|
2018-02-01 16:37:14 +00:00
|
|
|
})
|
|
|
|
}
|