diff options
author | Paul "TBBle" Hampson <Paul.Hampson@Pobox.com> | 2022-03-12 21:05:55 +1100 |
---|---|---|
committer | Paul "TBBle" Hampson <Paul.Hampson@Pobox.com> | 2022-03-27 13:23:48 +1100 |
commit | c60f70f112bb1b1b115097e55094719173297e7b (patch) | |
tree | cfb134d369737c483161f0b3ce7a44ee1a7ea118 /integration | |
parent | 8941dcfcc5db4aefc351cd5b5bb4d524823035c0 (diff) | |
download | docker-c60f70f112bb1b1b115097e55094719173297e7b.tar.gz |
Break out `setupWindowsDevices` and add tests
Since this function is about to get more complicated, and change
behaviour, this establishes tests for the existing implementation.
Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
Diffstat (limited to 'integration')
-rw-r--r-- | integration/container/devices_windows_test.go | 67 | ||||
-rw-r--r-- | integration/internal/container/ops.go | 14 |
2 files changed, 81 insertions, 0 deletions
diff --git a/integration/container/devices_windows_test.go b/integration/container/devices_windows_test.go new file mode 100644 index 0000000000..7c9c113aaa --- /dev/null +++ b/integration/container/devices_windows_test.go @@ -0,0 +1,67 @@ +package container // import "github.com/docker/docker/integration/container" + +import ( + "context" + "strings" + "testing" + "time" + + containertypes "github.com/docker/docker/api/types/container" + "github.com/docker/docker/integration/internal/container" + "gotest.tools/v3/assert" + "gotest.tools/v3/poll" + "gotest.tools/v3/skip" +) + +// TestWindowsDevices that Windows Devices are correctly propagated +// via HostConfig.Devices through to the implementation in hcsshim. +func TestWindowsDevices(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType != "windows") + defer setupTest(t)() + client := testEnv.APIClient() + ctx := context.Background() + + testData := []struct { + doc string + devices []string + expectedExitCode int + expectedStdout string + expectedStderr string + }{ + { + doc: "no device mounted", + expectedExitCode: 1, + }, + { + doc: "class/5B45201D-F2F2-4F3B-85BB-30FF1F953599 mounted", + devices: []string{"class/5B45201D-F2F2-4F3B-85BB-30FF1F953599"}, + expectedStdout: "/Windows/System32/HostDriverStore/FileRepository", + }, + } + + for _, d := range testData { + d := d + t.Run(d.doc, func(t *testing.T) { + t.Parallel() + deviceOptions := []func(*container.TestContainerConfig){container.WithIsolation(containertypes.IsolationProcess)} + for _, deviceName := range d.devices { + deviceOptions = append(deviceOptions, container.WithWindowsDevice(deviceName)) + } + id := container.Run(ctx, t, client, deviceOptions...) + + poll.WaitOn(t, container.IsInState(ctx, client, id, "running"), poll.WithDelay(100*time.Millisecond)) + + // /Windows/System32/HostDriverStore is mounted from the host when class GUID 5B45201D-F2F2-4F3B-85BB-30FF1F953599 + // is mounted. See `C:\windows\System32\containers\devices.def` on a Windows host for (slightly more) details. + res, err := container.Exec(ctx, client, id, []string{"sh", "-c", + "ls -d /Windows/System32/HostDriverStore/* | grep /Windows/System32/HostDriverStore/FileRepository"}) + assert.NilError(t, err) + assert.Equal(t, d.expectedExitCode, res.ExitCode) + if d.expectedExitCode == 0 { + assert.Equal(t, d.expectedStdout, strings.TrimSpace(res.Stdout())) + assert.Equal(t, d.expectedStderr, strings.TrimSpace(res.Stderr())) + } + + }) + } +} diff --git a/integration/internal/container/ops.go b/integration/internal/container/ops.go index dae5a2a512..0a600361aa 100644 --- a/integration/internal/container/ops.go +++ b/integration/internal/container/ops.go @@ -213,3 +213,17 @@ func WithPlatform(p *specs.Platform) func(*TestContainerConfig) { c.Platform = p } } + +// WithWindowsDevice specifies a Windows Device, ala `--device` on the CLI +func WithWindowsDevice(device string) func(*TestContainerConfig) { + return func(c *TestContainerConfig) { + c.HostConfig.Devices = append(c.HostConfig.Devices, containertypes.DeviceMapping{PathOnHost: device}) + } +} + +// WithIsolation specifies the isolation technology to apply to the container +func WithIsolation(isolation containertypes.Isolation) func(*TestContainerConfig) { + return func(c *TestContainerConfig) { + c.HostConfig.Isolation = isolation + } +} |