docker_cli_start_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "os/exec"
  4. "testing"
  5. "time"
  6. )
  7. // Regression test for https://github.com/docker/docker/issues/7843
  8. func TestStartAttachReturnsOnError(t *testing.T) {
  9. defer deleteAllContainers()
  10. cmd(t, "run", "-d", "--name", "test", "busybox")
  11. cmd(t, "stop", "test")
  12. // Expect this to fail because the above container is stopped, this is what we want
  13. if _, err := runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "test2", "--link", "test:test", "busybox")); err == nil {
  14. t.Fatal("Expected error but got none")
  15. }
  16. ch := make(chan struct{})
  17. go func() {
  18. // Attempt to start attached to the container that won't start
  19. // This should return an error immediately since the container can't be started
  20. if _, err := runCommand(exec.Command(dockerBinary, "start", "-a", "test2")); err == nil {
  21. t.Fatal("Expected error but got none")
  22. }
  23. close(ch)
  24. }()
  25. select {
  26. case <-ch:
  27. case <-time.After(time.Second):
  28. t.Fatalf("Attach did not exit properly")
  29. }
  30. logDone("start - error on start with attach exits")
  31. }