delete_test.go 961 B

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