1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/container/resize_test.go
Yong Tang eda311c18f Move containerIsStopped/containerIsInState to integration/internal/container
This fix moves helper functions containerIsStopped and
containerIsInState to integration/internal/container,
so that they could be used outside of integration/container.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2018-02-23 21:23:05 +00:00

64 lines
1.8 KiB
Go

package container // import "github.com/docker/docker/integration/container"
import (
"context"
"net/http"
"testing"
"time"
"github.com/docker/docker/api/types"
req "github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/integration/internal/request"
"github.com/docker/docker/internal/testutil"
"github.com/gotestyourself/gotestyourself/poll"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestResize(t *testing.T) {
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()
cID := container.Run(t, ctx, client)
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
err := client.ContainerResize(ctx, cID, types.ResizeOptions{
Height: 40,
Width: 40,
})
require.NoError(t, err)
}
func TestResizeWithInvalidSize(t *testing.T) {
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()
cID := container.Run(t, ctx, client)
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
endpoint := "/containers/" + cID + "/resize?h=foo&w=bar"
res, _, err := req.Post(endpoint)
require.NoError(t, err)
assert.Equal(t, res.StatusCode, http.StatusBadRequest)
}
func TestResizeWhenContainerNotStarted(t *testing.T) {
defer setupTest(t)()
client := request.NewAPIClient(t)
ctx := context.Background()
cID := container.Run(t, ctx, client, container.WithCmd("echo"))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond))
err := client.ContainerResize(ctx, cID, types.ResizeOptions{
Height: 40,
Width: 40,
})
testutil.ErrorContains(t, err, "is not running")
}