| 321 | } |
| 322 | |
| 323 | func TestCopyToContainerReportsEmptyFileSize(t *testing.T) { |
| 324 | srcFile := fs.NewFile(t, "cp-test-empty", fs.WithContent("")) |
| 325 | |
| 326 | fakeCli := test.NewFakeCli(&fakeClient{ |
| 327 | containerStatPathFunc: func(containerID, path string) (client.ContainerStatPathResult, error) { |
| 328 | return client.ContainerStatPathResult{ |
| 329 | Stat: container.PathStat{ |
| 330 | Name: "tmp", |
| 331 | Mode: os.ModeDir | 0o755, |
| 332 | }, |
| 333 | }, nil |
| 334 | }, |
| 335 | containerCopyToFunc: func(containerID string, options client.CopyToContainerOptions) (client.CopyToContainerResult, error) { |
| 336 | _, _ = io.Copy(io.Discard, options.Content) |
| 337 | return client.CopyToContainerResult{}, nil |
| 338 | }, |
| 339 | }) |
| 340 | err := runCopy(context.TODO(), fakeCli, copyOptions{ |
| 341 | source: srcFile.Path(), |
| 342 | destination: "container:/tmp", |
| 343 | }) |
| 344 | assert.NilError(t, err) |
| 345 | errOut := fakeCli.ErrBuffer().String() |
| 346 | assert.Check(t, is.Contains(errOut, "Successfully copied 0B")) |
| 347 | assert.Check(t, is.Contains(errOut, "(transferred")) |
| 348 | } |
| 349 | |
| 350 | func TestCopyToContainerReportsDirectorySize(t *testing.T) { |
| 351 | // Create a temp directory with files "aaa" (3 bytes) + "bbb" (3 bytes) = 6 bytes. |