docker_cli_export_import_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "os"
  4. "strings"
  5. "github.com/docker/docker/integration-cli/checker"
  6. "github.com/go-check/check"
  7. "gotest.tools/icmd"
  8. )
  9. // TODO: Move this test to docker/cli, as it is essentially the same test
  10. // as TestExportContainerAndImportImage except output to a file.
  11. // Used to test output flag in the export command
  12. func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
  13. testRequires(c, DaemonIsLinux)
  14. containerID := "testexportcontainerwithoutputandimportimage"
  15. dockerCmd(c, "run", "--name", containerID, "busybox", "true")
  16. dockerCmd(c, "export", "--output=testexp.tar", containerID)
  17. defer os.Remove("testexp.tar")
  18. resultCat := icmd.RunCommand("cat", "testexp.tar")
  19. resultCat.Assert(c, icmd.Success)
  20. result := icmd.RunCmd(icmd.Cmd{
  21. Command: []string{dockerBinary, "import", "-", "repo/testexp:v1"},
  22. Stdin: strings.NewReader(resultCat.Combined()),
  23. })
  24. result.Assert(c, icmd.Success)
  25. cleanedImageID := strings.TrimSpace(result.Combined())
  26. c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
  27. }