| 348 | } |
| 349 | |
| 350 | func TestCopyToContainerReportsDirectorySize(t *testing.T) { |
| 351 | // Create a temp directory with files "aaa" (3 bytes) + "bbb" (3 bytes) = 6 bytes. |
| 352 | // The TAR archive is much larger, but the success message should report 6B. |
| 353 | srcDir := fs.NewDir(t, "cp-test-dir", |
| 354 | fs.WithFile("aaa", "aaa"), |
| 355 | fs.WithFile("bbb", "bbb"), |
| 356 | ) |
| 357 | |
| 358 | fakeCli := test.NewFakeCli(&fakeClient{ |
| 359 | containerStatPathFunc: func(containerID, path string) (client.ContainerStatPathResult, error) { |
| 360 | return client.ContainerStatPathResult{ |
| 361 | Stat: container.PathStat{ |
| 362 | Name: "tmp", |
| 363 | Mode: os.ModeDir | 0o755, |
| 364 | }, |
| 365 | }, nil |
| 366 | }, |
| 367 | containerCopyToFunc: func(containerID string, options client.CopyToContainerOptions) (client.CopyToContainerResult, error) { |
| 368 | _, _ = io.Copy(io.Discard, options.Content) |
| 369 | return client.CopyToContainerResult{}, nil |
| 370 | }, |
| 371 | }) |
| 372 | err := runCopy(context.TODO(), fakeCli, copyOptions{ |
| 373 | source: srcDir.Path() + string(os.PathSeparator), |
| 374 | destination: "container:/tmp", |
| 375 | }) |
| 376 | assert.NilError(t, err) |
| 377 | errOut := fakeCli.ErrBuffer().String() |
| 378 | assert.Check(t, is.Contains(errOut, "Successfully copied 6B")) |
| 379 | assert.Check(t, is.Contains(errOut, "(transferred")) |
| 380 | } |
| 381 | |
| 382 | func TestCopyFromContainerReportsDirectorySize(t *testing.T) { |
| 383 | // When copying a directory from a container, cpRes.Stat.Mode.IsDir() is true, |