mirror of
https://github.com/moby/moby.git
synced 2026-08-04 15:11:00 +00:00
Move the useful Mounts API create coverage out of integration-cli and into the container integration tests that own the behavior. Add volume mount inspect assertions to TestContainerVolumeAnonymous for destination normalization, read-only named volumes, explicit driver configuration, and NoCopy mounts. Add a focused bind mount inspect test for read-only bind mounts and shared propagation. Do not port the full integration-cli matrix. Existing integration tests already cover anonymous volume creation and labeling, anonymous volume removal with RemoveVolumes, and generic bind propagation handling. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"math/rand"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Microsoft/go-winio"
|
|
"github.com/moby/moby/api/types/container"
|
|
"github.com/moby/moby/api/types/mount"
|
|
"github.com/moby/moby/api/types/network"
|
|
"github.com/moby/moby/client"
|
|
"github.com/moby/moby/v2/internal/testutil"
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func (s *DockerAPISuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T) {
|
|
// Create a host pipe to map into the container
|
|
hostPipeName := fmt.Sprintf(`\\.\pipe\docker-cli-test-pipe-%x`, rand.Uint64())
|
|
pc := &winio.PipeConfig{
|
|
SecurityDescriptor: "D:P(A;;GA;;;AU)", // Allow all users access to the pipe
|
|
}
|
|
l, err := winio.ListenPipe(hostPipeName, pc)
|
|
if err != nil {
|
|
c.Fatal(err)
|
|
}
|
|
defer l.Close()
|
|
|
|
// Asynchronously read data that the container writes to the mapped pipe.
|
|
var b []byte
|
|
ch := make(chan error)
|
|
go func() {
|
|
conn, err := l.Accept()
|
|
if err == nil {
|
|
b, err = io.ReadAll(conn)
|
|
conn.Close()
|
|
}
|
|
ch <- err
|
|
}()
|
|
|
|
containerPipeName := `\\.\pipe\docker-cli-test-pipe`
|
|
text := "hello from a pipe"
|
|
cmd := fmt.Sprintf("echo %s > %s", text, containerPipeName)
|
|
name := "test-bind-npipe"
|
|
|
|
ctx := testutil.GetContext(c)
|
|
apiClient := testEnv.APIClient()
|
|
_, err = apiClient.ContainerCreate(ctx,
|
|
client.ContainerCreateOptions{
|
|
Config: &container.Config{
|
|
Image: testEnv.PlatformDefaults.BaseImage,
|
|
Cmd: []string{"cmd", "/c", cmd},
|
|
},
|
|
HostConfig: &container.HostConfig{
|
|
Mounts: []mount.Mount{
|
|
{
|
|
Type: "npipe",
|
|
Source: hostPipeName,
|
|
Target: containerPipeName,
|
|
},
|
|
},
|
|
},
|
|
NetworkingConfig: &network.NetworkingConfig{},
|
|
Name: name,
|
|
},
|
|
)
|
|
assert.NilError(c, err)
|
|
|
|
_, err = apiClient.ContainerStart(ctx, name, client.ContainerStartOptions{})
|
|
assert.NilError(c, err)
|
|
|
|
err = <-ch
|
|
assert.NilError(c, err)
|
|
assert.Check(c, is.Equal(text, strings.TrimSpace(string(b))))
|
|
}
|