docker_cli_export_import_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "os"
  4. "strings"
  5. "github.com/docker/docker/integration-cli/checker"
  6. icmd "github.com/docker/docker/pkg/testutil/cmd"
  7. "github.com/go-check/check"
  8. )
  9. // export an image and try to import it into a new one
  10. func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
  11. testRequires(c, DaemonIsLinux)
  12. containerID := "testexportcontainerandimportimage"
  13. dockerCmd(c, "run", "--name", containerID, "busybox", "true")
  14. out, _ := dockerCmd(c, "export", containerID)
  15. result := icmd.RunCmd(icmd.Cmd{
  16. Command: dockerBinary, "import", "-", "repo/testexp:v1",
  17. Stdin: strings.NewReader(out),
  18. })
  19. result.Assert(c, icmd.Success)
  20. cleanedImageID := strings.TrimSpace(result.Combined())
  21. c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
  22. }
  23. // Used to test output flag in the export command
  24. func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
  25. testRequires(c, DaemonIsLinux)
  26. containerID := "testexportcontainerwithoutputandimportimage"
  27. dockerCmd(c, "run", "--name", containerID, "busybox", "true")
  28. dockerCmd(c, "export", "--output=testexp.tar", containerID)
  29. defer os.Remove("testexp.tar")
  30. resultCat := icmd.RunCommand("cat", "testexp.tar")
  31. resultCat.Assert(c, icmd.Success)
  32. result := icmd.RunCmd(icmd.Cmd{
  33. Command: dockerBinary, "import", "-", "repo/testexp:v1",
  34. Stdin: strings.NewReader(resultCat.Combined()),
  35. })
  36. result.Assert(c, icmd.Success)
  37. cleanedImageID := strings.TrimSpace(result.Combined())
  38. c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
  39. }