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>
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/internal/test"
|
|
"github.com/moby/moby/api/types/container"
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func TestRunCommit(t *testing.T) {
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
containerCommitFunc: func(
|
|
ctx context.Context,
|
|
ctr string,
|
|
options container.CommitOptions,
|
|
) (container.CommitResponse, error) {
|
|
assert.Check(t, is.Equal(options.Author, "Author Name <author@name.com>"))
|
|
assert.Check(t, is.DeepEqual(options.Changes, []string{"EXPOSE 80"}))
|
|
assert.Check(t, is.Equal(options.Comment, "commit message"))
|
|
assert.Check(t, is.Equal(options.Pause, false))
|
|
assert.Check(t, is.Equal(ctr, "container-id"))
|
|
|
|
return container.CommitResponse{ID: "image-id"}, nil
|
|
},
|
|
})
|
|
|
|
cmd := newCommitCommand(cli)
|
|
cmd.SetOut(io.Discard)
|
|
cmd.SetArgs(
|
|
[]string{
|
|
"--author", "Author Name <author@name.com>",
|
|
"--change", "EXPOSE 80",
|
|
"--message", "commit message",
|
|
"--pause=false",
|
|
"container-id",
|
|
},
|
|
)
|
|
|
|
err := cmd.Execute()
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.Equal(cli.OutBuffer().String(), "image-id\n"))
|
|
}
|
|
|
|
func TestRunCommitClientError(t *testing.T) {
|
|
clientError := errors.New("client error")
|
|
|
|
cli := test.NewFakeCli(&fakeClient{
|
|
containerCommitFunc: func(
|
|
ctx context.Context,
|
|
ctr string,
|
|
options container.CommitOptions,
|
|
) (container.CommitResponse, error) {
|
|
return container.CommitResponse{}, clientError
|
|
},
|
|
})
|
|
|
|
cmd := newCommitCommand(cli)
|
|
cmd.SetOut(io.Discard)
|
|
cmd.SetErr(io.Discard)
|
|
cmd.SetArgs([]string{"container-id"})
|
|
|
|
err := cmd.Execute()
|
|
assert.ErrorIs(t, err, clientError)
|
|
}
|