mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client/container_copy: Wrap options and result struct
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
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
|
||||
|
||||
@@ -607,7 +607,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
|
||||
|
||||
// Wait until container creates a file in the volume.
|
||||
poll.WaitOn(t, func(t poll.LogT) poll.Result {
|
||||
stat, err := c.ContainerStatPath(ctx, cID, "/foo/test.txt")
|
||||
res, err := c.ContainerStatPath(ctx, cID, client.ContainerStatPathOptions{Path: "/foo/test.txt"})
|
||||
if err != nil {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return poll.Continue("file doesn't yet exist")
|
||||
@@ -615,8 +615,8 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
|
||||
return poll.Error(err)
|
||||
}
|
||||
|
||||
if int(stat.Size) != len(testContent)+1 {
|
||||
return poll.Error(fmt.Errorf("unexpected test file size: %d", stat.Size))
|
||||
if int(res.Stat.Size) != len(testContent)+1 {
|
||||
return poll.Error(fmt.Errorf("unexpected test file size: %d", res.Stat.Size))
|
||||
}
|
||||
|
||||
return poll.Success()
|
||||
@@ -680,7 +680,7 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
|
||||
defer c.ContainerRemove(ctx, cID, client.ContainerRemoveOptions{Force: true})
|
||||
|
||||
waitFn := func(t poll.LogT) poll.Result {
|
||||
_, err := c.ContainerStatPath(ctx, cID, "/image/hello")
|
||||
_, err := c.ContainerStatPath(ctx, cID, client.ContainerStatPathOptions{Path: "/image/hello"})
|
||||
if err != nil {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return poll.Continue("file doesn't yet exist")
|
||||
|
||||
@@ -415,12 +415,12 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
|
||||
dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, archive.CopyInfo{Path: "/test"})
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = c.CopyToContainer(ctx, cID, dstDir, preparedArchive, client.CopyToContainerOptions{})
|
||||
_, err = c.CopyToContainer(ctx, cID, client.CopyToContainerOptions{DestinationPath: dstDir, Content: preparedArchive})
|
||||
assert.NilError(t, err)
|
||||
|
||||
rdr, _, err := c.CopyFromContainer(ctx, cID, "/test")
|
||||
res, err := c.CopyFromContainer(ctx, cID, client.CopyFromContainerOptions{SourcePath: "/test"})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(io.Discard, rdr)
|
||||
_, err = io.Copy(io.Discard, res.Content)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user