github.com/kunnos/engine@v1.13.1/daemon/delete_test.go (about)

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