github.com/mforkel/docker-ce-i386@v17.12.1-ce-rc2+incompatible/components/engine/daemon/oci_linux_test.go (about)

     1  package daemon
     2  
     3  import (
     4  	"testing"
     5  
     6  	containertypes "github.com/docker/docker/api/types/container"
     7  	"github.com/docker/docker/container"
     8  	"github.com/docker/docker/daemon/config"
     9  	"github.com/docker/docker/oci"
    10  	"github.com/docker/docker/pkg/idtools"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  // TestTmpfsDevShmNoDupMount checks that a user-specified /dev/shm tmpfs
    16  // mount (as in "docker run --tmpfs /dev/shm:rw,size=NNN") does not result
    17  // in "Duplicate mount point" error from the engine.
    18  // https://github.com/moby/moby/issues/35455
    19  func TestTmpfsDevShmNoDupMount(t *testing.T) {
    20  	d := Daemon{
    21  		// some empty structs to avoid getting a panic
    22  		// caused by a null pointer dereference
    23  		idMappings:  &idtools.IDMappings{},
    24  		configStore: &config.Config{},
    25  	}
    26  	c := &container.Container{
    27  		ShmPath: "foobar", // non-empty, for c.IpcMounts() to work
    28  		HostConfig: &containertypes.HostConfig{
    29  			IpcMode: containertypes.IpcMode("shareable"), // default mode
    30  			// --tmpfs /dev/shm:rw,exec,size=NNN
    31  			Tmpfs: map[string]string{
    32  				"/dev/shm": "rw,exec,size=1g",
    33  			},
    34  		},
    35  	}
    36  
    37  	// Mimick the code flow of daemon.createSpec(), enough to reproduce the issue
    38  	ms, err := d.setupMounts(c)
    39  	assert.NoError(t, err)
    40  
    41  	ms = append(ms, c.IpcMounts()...)
    42  
    43  	tmpfsMounts, err := c.TmpfsMounts()
    44  	assert.NoError(t, err)
    45  	ms = append(ms, tmpfsMounts...)
    46  
    47  	s := oci.DefaultSpec()
    48  	err = setMounts(&d, &s, c, ms)
    49  	assert.NoError(t, err)
    50  }