docker_cli_commit_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "testing"
  6. )
  7. func TestCommitAfterContainerIsDone(t *testing.T) {
  8. runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
  9. out, _, _, err := runCommandWithStdoutStderr(runCmd)
  10. errorOut(err, t, fmt.Sprintf("failed to run container: %v %v", out, err))
  11. cleanedContainerID := stripTrailingCharacters(out)
  12. waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
  13. _, _, err = runCommandWithOutput(waitCmd)
  14. errorOut(err, t, fmt.Sprintf("error thrown while waiting for container: %s", out))
  15. commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID)
  16. out, _, err = runCommandWithOutput(commitCmd)
  17. errorOut(err, t, fmt.Sprintf("failed to commit container to image: %v %v", out, err))
  18. cleanedImageID := stripTrailingCharacters(out)
  19. inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
  20. out, _, err = runCommandWithOutput(inspectCmd)
  21. errorOut(err, t, fmt.Sprintf("failed to inspect image: %v %v", out, err))
  22. deleteContainer(cleanedContainerID)
  23. deleteImages(cleanedImageID)
  24. logDone("commit - echo foo and commit the image")
  25. }