MCPcopy Index your code
hub / github.com/ddev/ddev / TestCopyIntoContainer

Function TestCopyIntoContainer

pkg/dockerutil/containers_test.go:555–588  ·  view source on GitHub ↗

TestCopyIntoContainer makes sure CopyIntoContainer copies a local file or directory into a specified path in container

(t *testing.T)

Source from the content-addressed store, hash-verified

553// TestCopyIntoContainer makes sure CopyIntoContainer copies a local file or directory into a specified
554// path in container
555func TestCopyIntoContainer(t *testing.T) {
556 assert := asrt.New(t)
557 pwd, _ := os.Getwd()
558
559 cid, err := dockerutil.FindContainerByName(testContainerName)
560 require.NoError(t, err)
561 require.NotNil(t, cid)
562
563 uid, _, _ := dockerutil.GetContainerUser()
564 targetDir, _, err := dockerutil.Exec(cid.ID, "mktemp -d", uid)
565 require.NoError(t, err)
566 targetDir = strings.Trim(targetDir, "\n")
567
568 err = dockerutil.CopyIntoContainer(filepath.Join(pwd, "testdata", t.Name()), testContainerName, targetDir, "")
569 require.NoError(t, err)
570
571 out, _, err := dockerutil.Exec(cid.ID, fmt.Sprintf(`bash -c "cd %s && ls -R * .test.sh && ./.test.sh"`, targetDir), uid)
572 require.NoError(t, err)
573 assert.Equal(`.test.sh
574root.txt
575
576subdir1:
577subdir1.txt
578hi this is a test file
579`, out)
580
581 // Now try a file
582 err = dockerutil.CopyIntoContainer(filepath.Join(pwd, "testdata", t.Name(), "root.txt"), testContainerName, "/tmp", "")
583 require.NoError(t, err)
584
585 out, _, err = dockerutil.Exec(cid.ID, `cat /tmp/root.txt`, uid)
586 require.NoError(t, err)
587 assert.Equal("root.txt here\n", out)
588}
589
590// TestCopyFromContainer makes sure CopyFromContainer copies a container into a specified
591// local directory

Callers

nothing calls this directly

Calls 4

FindContainerByNameFunction · 0.92
GetContainerUserFunction · 0.92
ExecFunction · 0.92
CopyIntoContainerFunction · 0.92

Tested by

no test coverage detected