Skip to content

Commit 8c0cb30

Browse files
committed
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 <[email protected]>
1 parent 3b49deb commit 8c0cb30

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cli/command/container/cp_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ func TestRunCopyFromContainerToStdout(t *testing.T) {
6666
}
6767

6868
func TestRunCopyFromContainerToFilesystem(t *testing.T) {
69-
destDir := fs.NewDir(t, "cp-test",
69+
srcDir := fs.NewDir(t, "cp-test",
7070
fs.WithFile("file1", "content\n"))
71-
defer destDir.Remove()
71+
72+
destDir := fs.NewDir(t, "cp-test")
7273

7374
cli := test.NewFakeCli(&fakeClient{
7475
containerCopyFromFunc: func(ctr, srcPath string) (io.ReadCloser, container.PathStat, error) {
7576
assert.Check(t, is.Equal("container", ctr))
76-
readCloser, err := archive.Tar(destDir.Path(), archive.Uncompressed)
77+
readCloser, err := archive.Tar(srcDir.Path(), archive.Uncompressed)
7778
return readCloser, container.PathStat{}, err
7879
},
7980
})

0 commit comments

Comments
 (0)