mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51315 from austinvazquez/refactor-client-container-rename
client: refactor `ContainerRename` to wrap options/result structs
This commit is contained in:
@@ -66,7 +66,7 @@ type ContainerAPIClient interface {
|
||||
ContainerLogs(ctx context.Context, container string, options ContainerLogsOptions) (ContainerLogsResult, error)
|
||||
ContainerPause(ctx context.Context, container string, options ContainerPauseOptions) (ContainerPauseResult, error)
|
||||
ContainerRemove(ctx context.Context, container string, options ContainerRemoveOptions) (ContainerRemoveResult, error)
|
||||
ContainerRename(ctx context.Context, container, newContainerName string) error
|
||||
ContainerRename(ctx context.Context, container string, options ContainerRenameOptions) (ContainerRenameResult, error)
|
||||
ContainerResize(ctx context.Context, container string, options ContainerResizeOptions) (ContainerResizeResult, error)
|
||||
ContainerRestart(ctx context.Context, container string, options ContainerRestartOptions) (ContainerRestartResult, error)
|
||||
ContainerStatPath(ctx context.Context, container, path string) (container.PathStat, error)
|
||||
|
||||
@@ -5,16 +5,26 @@ import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// ContainerRenameOptions represents the options for renaming a container.
|
||||
type ContainerRenameOptions struct {
|
||||
NewName string
|
||||
}
|
||||
|
||||
// ContainerRenameResult represents the result of a container rename operation.
|
||||
type ContainerRenameResult struct {
|
||||
// This struct can be expanded in the future if needed
|
||||
}
|
||||
|
||||
// ContainerRename changes the name of a given container.
|
||||
func (cli *Client) ContainerRename(ctx context.Context, containerID, newContainerName string) error {
|
||||
func (cli *Client) ContainerRename(ctx context.Context, containerID string, options ContainerRenameOptions) (ContainerRenameResult, error) {
|
||||
containerID, err := trimID("container", containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
return ContainerRenameResult{}, err
|
||||
}
|
||||
|
||||
query := url.Values{}
|
||||
query.Set("name", newContainerName)
|
||||
query.Set("name", options.NewName)
|
||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/rename", query, nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
return err
|
||||
return ContainerRenameResult{}, err
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ import (
|
||||
func TestContainerRenameError(t *testing.T) {
|
||||
client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusInternalServerError, "Server error")))
|
||||
assert.NilError(t, err)
|
||||
err = client.ContainerRename(context.Background(), "nothing", "newNothing")
|
||||
_, err = client.ContainerRename(context.Background(), "nothing", ContainerRenameOptions{NewName: "newNothing"})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
|
||||
err = client.ContainerRename(context.Background(), "", "newNothing")
|
||||
_, err = client.ContainerRename(context.Background(), "", ContainerRenameOptions{NewName: "newNothing"})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
|
||||
err = client.ContainerRename(context.Background(), " ", "newNothing")
|
||||
_, err = client.ContainerRename(context.Background(), " ", ContainerRenameOptions{NewName: "newNothing"})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
}
|
||||
@@ -40,6 +40,6 @@ func TestContainerRename(t *testing.T) {
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = client.ContainerRename(context.Background(), "container_id", "newName")
|
||||
_, err = client.ContainerRename(context.Background(), "container_id", ContainerRenameOptions{NewName: "newName"})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user