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

Function TestCopyFromContainerReportsFileSize

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

Source from the content-addressed store, hash-verified

259}
260
261func 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
293func TestCopyToContainerReportsFileSize(t *testing.T) {
294 // Create a temp file with known content ("hello" = 5 bytes).

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…