docker_cli_import_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "os/exec"
  4. "strings"
  5. "github.com/go-check/check"
  6. )
  7. func (s *DockerSuite) TestImportDisplay(c *check.C) {
  8. runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
  9. out, _, err := runCommandWithOutput(runCmd)
  10. if err != nil {
  11. c.Fatal("failed to create a container", out, err)
  12. }
  13. cleanedContainerID := strings.TrimSpace(out)
  14. out, _, err = runCommandPipelineWithOutput(
  15. exec.Command(dockerBinary, "export", cleanedContainerID),
  16. exec.Command(dockerBinary, "import", "-"),
  17. )
  18. if err != nil {
  19. c.Errorf("import failed with errors: %v, output: %q", err, out)
  20. }
  21. if n := strings.Count(out, "\n"); n != 1 {
  22. c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
  23. }
  24. image := strings.TrimSpace(out)
  25. defer deleteImages(image)
  26. runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
  27. out, _, err = runCommandWithOutput(runCmd)
  28. if err != nil {
  29. c.Fatal("failed to create a container", out, err)
  30. }
  31. if out != "" {
  32. c.Fatalf("command output should've been nothing, was %q", out)
  33. }
  34. }