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 <derek@mcg.dev>
This commit is contained in:
Derek McGowan 2024-12-26 16:14:45 -08:00
parent 3b49deb8fc
commit 8c0cb30515

View File

@ -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
},
})