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