github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/container/tty_test.go (about)

     1  package container
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/docker/cli/cli/command"
     9  	"github.com/docker/cli/internal/test"
    10  	"github.com/docker/docker/api/types"
    11  	"github.com/pkg/errors"
    12  	"gotest.tools/v3/assert"
    13  	is "gotest.tools/v3/assert/cmp"
    14  )
    15  
    16  func TestInitTtySizeErrors(t *testing.T) {
    17  	expectedError := "failed to resize tty, using default size\n"
    18  	fakeContainerExecResizeFunc := func(id string, options types.ResizeOptions) error {
    19  		return errors.Errorf("Error response from daemon: no such exec")
    20  	}
    21  	fakeResizeTtyFunc := func(ctx context.Context, cli command.Cli, id string, isExec bool) error {
    22  		height, width := uint(1024), uint(768)
    23  		return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec)
    24  	}
    25  	ctx := context.Background()
    26  	cli := test.NewFakeCli(&fakeClient{containerExecResizeFunc: fakeContainerExecResizeFunc})
    27  	initTtySize(ctx, cli, "8mm8nn8tt8bb", true, fakeResizeTtyFunc)
    28  	time.Sleep(100 * time.Millisecond)
    29  	assert.Check(t, is.Equal(expectedError, cli.ErrBuffer().String()))
    30  }