delete_test.go 1.1 KB

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