delete_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package daemon
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "testing"
  6. "github.com/docker/docker/container"
  7. "github.com/docker/engine-api/types"
  8. containertypes "github.com/docker/engine-api/types/container"
  9. )
  10. func TestContainerDoubleDelete(t *testing.T) {
  11. tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. defer os.RemoveAll(tmp)
  16. daemon := &Daemon{
  17. repository: tmp,
  18. root: tmp,
  19. }
  20. daemon.containers = container.NewMemoryStore()
  21. container := &container.Container{
  22. CommonContainer: container.CommonContainer{
  23. ID: "test",
  24. State: container.NewState(),
  25. Config: &containertypes.Config{},
  26. },
  27. }
  28. daemon.containers.Add(container.ID, container)
  29. // Mark the container as having a delete in progress
  30. container.SetRemovalInProgress()
  31. // Try to remove the container when its start is removalInProgress.
  32. // It should ignore the container and not return an error.
  33. if err := daemon.ContainerRm(container.ID, &types.ContainerRmConfig{ForceRemove: true}); err != nil {
  34. t.Fatal(err)
  35. }
  36. }