docker_cli_import_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
  26. out, _, err = runCommandWithOutput(runCmd)
  27. if err != nil {
  28. c.Fatal("failed to create a container", out, err)
  29. }
  30. if out != "" {
  31. c.Fatalf("command output should've been nothing, was %q", out)
  32. }
  33. }