docker_cli_import_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. defer deleteContainer(cleanedContainerID)
  15. out, _, err = runCommandPipelineWithOutput(
  16. exec.Command(dockerBinary, "export", cleanedContainerID),
  17. exec.Command(dockerBinary, "import", "-"),
  18. )
  19. if err != nil {
  20. c.Errorf("import failed with errors: %v, output: %q", err, out)
  21. }
  22. if n := strings.Count(out, "\n"); n != 1 {
  23. c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
  24. }
  25. image := strings.TrimSpace(out)
  26. defer deleteImages(image)
  27. runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
  28. out, _, err = runCommandWithOutput(runCmd)
  29. if err != nil {
  30. c.Fatal("failed to create a container", out, err)
  31. }
  32. if out != "" {
  33. c.Fatalf("command output should've been nothing, was %q", out)
  34. }
  35. }