docker_cli_import_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }
  34. func (s *DockerSuite) TestImportBadURL(c *check.C) {
  35. runCmd := exec.Command(dockerBinary, "import", "http://nourl/bad")
  36. out, _, err := runCommandWithOutput(runCmd)
  37. if err == nil {
  38. c.Fatal("import was supposed to fail but didn't")
  39. }
  40. if !strings.Contains(out, "dial tcp") {
  41. c.Fatalf("expected an error msg but didn't get one:\n%s", out)
  42. }
  43. }