| 291 | } |
| 292 | |
| 293 | func TestCopyToContainerReportsFileSize(t *testing.T) { |
| 294 | // Create a temp file with known content ("hello" = 5 bytes). |
| 295 | // The TAR archive sent to the container is larger, but the success |
| 296 | // message should report the actual content size. |
| 297 | srcFile := fs.NewFile(t, "cp-test-to", fs.WithContent("hello")) |
| 298 | |
| 299 | fakeCli := test.NewFakeCli(&fakeClient{ |
| 300 | containerStatPathFunc: func(containerID, path string) (client.ContainerStatPathResult, error) { |
| 301 | return client.ContainerStatPathResult{ |
| 302 | Stat: container.PathStat{ |
| 303 | Name: "tmp", |
| 304 | Mode: os.ModeDir | 0o755, |
| 305 | }, |
| 306 | }, nil |
| 307 | }, |
| 308 | containerCopyToFunc: func(containerID string, options client.CopyToContainerOptions) (client.CopyToContainerResult, error) { |
| 309 | _, _ = io.Copy(io.Discard, options.Content) |
| 310 | return client.CopyToContainerResult{}, nil |
| 311 | }, |
| 312 | }) |
| 313 | err := runCopy(context.TODO(), fakeCli, copyOptions{ |
| 314 | source: srcFile.Path(), |
| 315 | destination: "container:/tmp", |
| 316 | }) |
| 317 | assert.NilError(t, err) |
| 318 | errOut := fakeCli.ErrBuffer().String() |
| 319 | assert.Check(t, is.Contains(errOut, "Successfully copied 5B")) |
| 320 | assert.Check(t, is.Contains(errOut, "(transferred")) |
| 321 | } |
| 322 | |
| 323 | func TestCopyToContainerReportsEmptyFileSize(t *testing.T) { |
| 324 | srcFile := fs.NewFile(t, "cp-test-empty", fs.WithContent("")) |