moby/integration/container/resize_test.go
Sebastiaan van Stijn 26be2bc6b9
integration/container: use consistent name for api-client
The `client` variable was colliding with the `client` import in various
files. While it didn't conflict in all files, there was inconsistency
in the naming, sometimes using the confusing `cli` name (it's not the
"cli"), and such names can easily start spreading (through copy/paste,
or "code by example").

Let's make a one-time pass through all of them in this package to use
the same name.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-11 13:51:57 +02:00

65 lines
1.9 KiB
Go

package container // import "github.com/docker/docker/integration/container"
import (
"context"
"net/http"
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration/internal/container"
req "github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/poll"
"gotest.tools/v3/skip"
)
func TestResize(t *testing.T) {
defer setupTest(t)()
apiClient := testEnv.APIClient()
ctx := context.Background()
cID := container.Run(ctx, t, apiClient, container.WithTty(true))
poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "running"), poll.WithDelay(100*time.Millisecond))
err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
Height: 40,
Width: 40,
})
assert.NilError(t, err)
}
func TestResizeWithInvalidSize(t *testing.T) {
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.32"), "broken in earlier versions")
defer setupTest(t)()
apiClient := testEnv.APIClient()
ctx := context.Background()
cID := container.Run(ctx, t, apiClient)
poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "running"), poll.WithDelay(100*time.Millisecond))
endpoint := "/containers/" + cID + "/resize?h=foo&w=bar"
res, _, err := req.Post(endpoint)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode))
}
func TestResizeWhenContainerNotStarted(t *testing.T) {
defer setupTest(t)()
apiClient := testEnv.APIClient()
ctx := context.Background()
cID := container.Run(ctx, t, apiClient, container.WithCmd("echo"))
poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "exited"), poll.WithDelay(100*time.Millisecond))
err := apiClient.ContainerResize(ctx, cID, types.ResizeOptions{
Height: 40,
Width: 40,
})
assert.Check(t, is.ErrorContains(err, "is not running"))
}