mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51328 from vvoland/client-containercopy-structs
client/container_copy: Wrap options and result struct
This commit is contained in:
@@ -30,7 +30,7 @@ func TestCopyFromContainerPathDoesNotExist(t *testing.T) {
|
||||
apiClient := testEnv.APIClient()
|
||||
cid := container.Create(ctx, t, apiClient)
|
||||
|
||||
_, _, err := apiClient.CopyFromContainer(ctx, cid, "/dne")
|
||||
_, err := apiClient.CopyFromContainer(ctx, cid, client.CopyFromContainerOptions{SourcePath: "/dne"})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorContains(err, "Could not find the file /dne in container "+cid))
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func TestCopyFromContainerPathIsNotDir(t *testing.T) {
|
||||
"The filename, directory name, or volume label syntax is incorrect.", // ERROR_INVALID_NAME
|
||||
}
|
||||
}
|
||||
_, _, err := apiClient.CopyFromContainer(ctx, cid, existingFile)
|
||||
_, err := apiClient.CopyFromContainer(ctx, cid, client.CopyFromContainerOptions{SourcePath: existingFile})
|
||||
var found bool
|
||||
for _, expErr := range expected {
|
||||
if err != nil && strings.Contains(err.Error(), expErr) {
|
||||
@@ -75,7 +75,7 @@ func TestCopyToContainerPathDoesNotExist(t *testing.T) {
|
||||
apiClient := testEnv.APIClient()
|
||||
cid := container.Create(ctx, t, apiClient)
|
||||
|
||||
err := apiClient.CopyToContainer(ctx, cid, "/dne", nil, client.CopyToContainerOptions{})
|
||||
_, err := apiClient.CopyToContainer(ctx, cid, client.CopyToContainerOptions{DestinationPath: "/dne", Content: bytes.NewReader([]byte(""))})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
assert.Check(t, is.ErrorContains(err, "Could not find the file /dne in container "+cid))
|
||||
}
|
||||
@@ -88,23 +88,22 @@ func TestCopyEmptyFile(t *testing.T) {
|
||||
|
||||
// empty content
|
||||
dstDir, _ := makeEmptyArchive(t)
|
||||
err := apiClient.CopyToContainer(ctx, cid, dstDir, bytes.NewReader([]byte("")), client.CopyToContainerOptions{})
|
||||
_, err := apiClient.CopyToContainer(ctx, cid, client.CopyToContainerOptions{DestinationPath: dstDir, Content: bytes.NewReader([]byte(""))})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// tar with empty file
|
||||
dstDir, preparedArchive := makeEmptyArchive(t)
|
||||
err = apiClient.CopyToContainer(ctx, cid, dstDir, preparedArchive, client.CopyToContainerOptions{})
|
||||
_, err = apiClient.CopyToContainer(ctx, cid, client.CopyToContainerOptions{DestinationPath: dstDir, Content: preparedArchive})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// tar with empty file archive mode
|
||||
dstDir, preparedArchive = makeEmptyArchive(t)
|
||||
err = apiClient.CopyToContainer(ctx, cid, dstDir, preparedArchive, client.CopyToContainerOptions{
|
||||
CopyUIDGID: true,
|
||||
})
|
||||
_, err = apiClient.CopyToContainer(ctx, cid, client.CopyToContainerOptions{DestinationPath: dstDir, Content: preparedArchive, CopyUIDGID: true})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// copy from empty file
|
||||
rdr, _, err := apiClient.CopyFromContainer(ctx, cid, dstDir)
|
||||
res, err := apiClient.CopyFromContainer(ctx, cid, client.CopyFromContainerOptions{SourcePath: dstDir})
|
||||
rdr := res.Content
|
||||
assert.NilError(t, err)
|
||||
defer rdr.Close()
|
||||
}
|
||||
@@ -189,9 +188,7 @@ func TestCopyToContainerCopyUIDGID(t *testing.T) {
|
||||
|
||||
// tar with empty file
|
||||
dstDir, preparedArchive := makeEmptyArchive(t)
|
||||
err := apiClient.CopyToContainer(ctx, cID, dstDir, preparedArchive, client.CopyToContainerOptions{
|
||||
CopyUIDGID: true,
|
||||
})
|
||||
_, err := apiClient.CopyToContainer(ctx, cID, client.CopyToContainerOptions{DestinationPath: dstDir, Content: preparedArchive, CopyUIDGID: true})
|
||||
assert.NilError(t, err)
|
||||
|
||||
res, err := container.Exec(ctx, apiClient, cID, []string{"stat", "-c", "%u:%g", "/empty-file.txt"})
|
||||
@@ -264,7 +261,7 @@ func TestCopyToContainerPathIsNotDir(t *testing.T) {
|
||||
if testEnv.DaemonInfo.OSType == "windows" {
|
||||
path = "c:/windows/system32/drivers/etc/hosts/"
|
||||
}
|
||||
err := apiClient.CopyToContainer(ctx, cid, path, nil, client.CopyToContainerOptions{})
|
||||
_, err := apiClient.CopyToContainer(ctx, cid, client.CopyToContainerOptions{DestinationPath: path})
|
||||
assert.Check(t, is.ErrorContains(err, "not a directory"))
|
||||
}
|
||||
|
||||
@@ -327,7 +324,8 @@ func TestCopyFromContainer(t *testing.T) {
|
||||
{"bar/notarget", map[string]string{"notarget": ""}},
|
||||
} {
|
||||
t.Run(x.src, func(t *testing.T) {
|
||||
rdr, _, err := apiClient.CopyFromContainer(ctx, cid, x.src)
|
||||
res, err := apiClient.CopyFromContainer(ctx, cid, client.CopyFromContainerOptions{SourcePath: x.src})
|
||||
rdr := res.Content
|
||||
assert.NilError(t, err)
|
||||
defer rdr.Close()
|
||||
|
||||
|
||||
@@ -480,7 +480,7 @@ func TestContainerCopyLeaksMounts(t *testing.T) {
|
||||
|
||||
mountsBefore := getMounts()
|
||||
|
||||
_, _, err := apiClient.CopyFromContainer(ctx, cid, "/etc/passwd")
|
||||
_, err := apiClient.CopyFromContainer(ctx, cid, client.CopyFromContainerOptions{SourcePath: "/etc/passwd"})
|
||||
assert.NilError(t, err)
|
||||
|
||||
mountsAfter := getMounts()
|
||||
|
||||
@@ -42,13 +42,14 @@ func TestNoOverlayfsWarningsAboutUndefinedBehaviors(t *testing.T) {
|
||||
{name: "cp to container", operation: func(t *testing.T) error {
|
||||
archiveReader, err := archive.Generate("new-file", "hello-world")
|
||||
assert.NilError(t, err, "failed to create a temporary archive")
|
||||
return apiClient.CopyToContainer(ctx, cID, "/", archiveReader, client.CopyToContainerOptions{})
|
||||
_, err = apiClient.CopyToContainer(ctx, cID, client.CopyToContainerOptions{DestinationPath: "/", Content: archiveReader})
|
||||
return err
|
||||
}},
|
||||
{name: "cp from container", operation: func(*testing.T) error {
|
||||
rc, _, err := apiClient.CopyFromContainer(ctx, cID, "/file")
|
||||
res, err := apiClient.CopyFromContainer(ctx, cID, client.CopyFromContainerOptions{SourcePath: "/file"})
|
||||
if err == nil {
|
||||
defer rc.Close()
|
||||
_, err = io.Copy(io.Discard, rc)
|
||||
defer res.Content.Close()
|
||||
_, err = io.Copy(io.Discard, res.Content)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user