This patch deprecates exported container commands and moves the implementation details to an unexported function. Commands that are affected include: - container.NewRunCommand - container.NewExecCommand - container.NewPsCommand - container.NewContainerCommand - container.NewAttachCommand - container.NewCommitCommand - container.NewCopyCommand - container.NewCreateCommand - container.NewDiffCommand - container.NewExportCommand - container.NewKillCommand - container.NewLogsCommand - container.NewPauseCommand - container.NewPortCommand - container.NewRenameCommand - container.NewRestartCommand - container.NewRmCommand - container.NewStartCommand - container.NewStatsCommand - container.NewStopCommand - container.NewTopCommand - container.NewUnpauseCommand - container.NewUpdateCommand - container.NewWaitCommand - container.NewPruneCommand Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/internal/test"
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func TestRunKill(t *testing.T) {
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
containerKillFunc: func(
|
|
ctx context.Context,
|
|
container string,
|
|
signal string,
|
|
) error {
|
|
assert.Assert(t, is.Equal(signal, "STOP"))
|
|
return nil
|
|
},
|
|
})
|
|
|
|
cmd := newKillCommand(cli)
|
|
cmd.SetOut(io.Discard)
|
|
|
|
cmd.SetArgs([]string{
|
|
"--signal", "STOP",
|
|
"container-id-1",
|
|
"container-id-2",
|
|
})
|
|
err := cmd.Execute()
|
|
assert.NilError(t, err)
|
|
|
|
containerIDs := strings.SplitN(cli.OutBuffer().String(), "\n", 2)
|
|
assert.Assert(t, is.Len(containerIDs, 2))
|
|
|
|
containerID1 := strings.TrimSpace(containerIDs[0])
|
|
containerID2 := strings.TrimSpace(containerIDs[1])
|
|
|
|
assert.Check(t, is.Equal(containerID1, "container-id-1"))
|
|
assert.Check(t, is.Equal(containerID2, "container-id-2"))
|
|
}
|
|
|
|
func TestRunKillClientError(t *testing.T) {
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
containerKillFunc: func(
|
|
ctx context.Context,
|
|
container string,
|
|
signal string,
|
|
) error {
|
|
return fmt.Errorf("client error for container %s", container)
|
|
},
|
|
})
|
|
|
|
cmd := newKillCommand(cli)
|
|
cmd.SetOut(io.Discard)
|
|
cmd.SetErr(io.Discard)
|
|
|
|
cmd.SetArgs([]string{"container-id-1", "container-id-2"})
|
|
err := cmd.Execute()
|
|
|
|
errs := strings.SplitN(err.Error(), "\n", 2)
|
|
assert.Assert(t, is.Len(errs, 2))
|
|
|
|
errContainerID1 := errs[0]
|
|
errContainerID2 := errs[1]
|
|
|
|
assert.Assert(t, is.Equal(errContainerID1, "client error for container container-id-1"))
|
|
assert.Assert(t, is.Equal(errContainerID2, "client error for container container-id-2"))
|
|
}
|