TestCopyIntoContainer makes sure CopyIntoContainer copies a local file or directory into a specified path in container
(t *testing.T)
| 553 | // TestCopyIntoContainer makes sure CopyIntoContainer copies a local file or directory into a specified |
| 554 | // path in container |
| 555 | func 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 |
| 574 | root.txt |
| 575 | |
| 576 | subdir1: |
| 577 | subdir1.txt |
| 578 | hi 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 |
nothing calls this directly
no test coverage detected