MCPcopy Index your code
hub / github.com/docker/cli / TestCopyToContainerReportsFileSize

Function TestCopyToContainerReportsFileSize

cli/command/container/cp_test.go:293–321  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

291}
292
293func 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
323func TestCopyToContainerReportsEmptyFileSize(t *testing.T) {
324 srcFile := fs.NewFile(t, "cp-test-empty", fs.WithContent(""))

Callers

nothing calls this directly

Calls 5

ErrBufferMethod · 0.95
runCopyFunction · 0.85
ContainsMethod · 0.80
PathMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…