From 8c0cb30515d24b774e40b0a9bacceae56709a46c Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 26 Dec 2024 16:14:45 -0800 Subject: [PATCH] Fix cp test to separate source and destination Currently the cp will tar from the same directory it will untar into simultaneously. There is a race between reading the file and truncating the file for write, however, the race will not show up with a large enough buffer on the tar side if buffered before the copy begins. Also removes the unnecessary deferred removal, the removal is handled by cleanup and respects the no cleanup env. Signed-off-by: Derek McGowan --- cli/command/container/cp_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/command/container/cp_test.go b/cli/command/container/cp_test.go index 1730f3863479..818605e524eb 100644 --- a/cli/command/container/cp_test.go +++ b/cli/command/container/cp_test.go @@ -66,14 +66,15 @@ func TestRunCopyFromContainerToStdout(t *testing.T) { } func TestRunCopyFromContainerToFilesystem(t *testing.T) { - destDir := fs.NewDir(t, "cp-test", + srcDir := fs.NewDir(t, "cp-test", fs.WithFile("file1", "content\n")) - defer destDir.Remove() + + destDir := fs.NewDir(t, "cp-test") cli := test.NewFakeCli(&fakeClient{ containerCopyFromFunc: func(ctr, srcPath string) (io.ReadCloser, container.PathStat, error) { assert.Check(t, is.Equal("container", ctr)) - readCloser, err := archive.Tar(destDir.Path(), archive.Uncompressed) + readCloser, err := archive.Tar(srcDir.Path(), archive.Uncompressed) return readCloser, container.PathStat{}, err }, })