| 259 | } |
| 260 | |
| 261 | func TestCopyFromContainerReportsFileSize(t *testing.T) { |
| 262 | // The file content is "hello" (5 bytes), but the TAR archive wrapping |
| 263 | // it is much larger due to headers and padding. The success message |
| 264 | // should report the actual file size (5B), not the TAR stream size. |
| 265 | srcDir := fs.NewDir(t, "cp-test-from", |
| 266 | fs.WithFile("file1", "hello")) |
| 267 | |
| 268 | destDir := fs.NewDir(t, "cp-test-from-dest") |
| 269 | |
| 270 | const fileSize int64 = 5 |
| 271 | fakeCli := test.NewFakeCli(&fakeClient{ |
| 272 | containerCopyFromFunc: func(ctr, srcPath string) (client.CopyFromContainerResult, error) { |
| 273 | readCloser, err := archive.Tar(srcDir.Path(), compression.None) |
| 274 | return client.CopyFromContainerResult{ |
| 275 | Content: readCloser, |
| 276 | Stat: container.PathStat{ |
| 277 | Name: "file1", |
| 278 | Size: fileSize, |
| 279 | }, |
| 280 | }, err |
| 281 | }, |
| 282 | }) |
| 283 | err := runCopy(context.TODO(), fakeCli, copyOptions{ |
| 284 | source: "container:/file1", |
| 285 | destination: destDir.Path(), |
| 286 | }) |
| 287 | assert.NilError(t, err) |
| 288 | errOut := fakeCli.ErrBuffer().String() |
| 289 | assert.Check(t, is.Contains(errOut, "Successfully copied 5B")) |
| 290 | assert.Check(t, is.Contains(errOut, "(transferred")) |
| 291 | } |
| 292 | |
| 293 | func TestCopyToContainerReportsFileSize(t *testing.T) { |
| 294 | // Create a temp file with known content ("hello" = 5 bytes). |