|
17 | 17 | package container |
18 | 18 |
|
19 | 19 | import ( |
| 20 | + "errors" |
20 | 21 | "fmt" |
21 | 22 | "os" |
| 23 | + "strings" |
22 | 24 | "testing" |
23 | 25 |
|
24 | 26 | "gotest.tools/v3/assert" |
25 | 27 |
|
| 28 | + "github.com/containerd/nerdctl/mod/tigron/expect" |
| 29 | + "github.com/containerd/nerdctl/mod/tigron/test" |
| 30 | + "github.com/containerd/nerdctl/mod/tigron/tig" |
| 31 | + |
26 | 32 | "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat" |
27 | 33 | "github.com/containerd/nerdctl/v2/pkg/testutil" |
| 34 | + "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" |
28 | 35 | ) |
29 | 36 |
|
30 | 37 | func TestRunMountVolume(t *testing.T) { |
@@ -213,3 +220,30 @@ func TestRunMountVolumeSpec(t *testing.T) { |
213 | 220 | // If -v is an empty string, it will be ignored |
214 | 221 | base.Cmd("run", "--rm", "-v", "", testutil.CommonImage).AssertOK() |
215 | 222 | } |
| 223 | + |
| 224 | +func TestRunVolumeWithDriveRootDestination(t *testing.T) { |
| 225 | + testCase := nerdtest.Setup() |
| 226 | + |
| 227 | + testCase.Cleanup = func(data test.Data, helpers test.Helpers) { |
| 228 | + helpers.Anyhow("rm", "-f", data.Identifier()) |
| 229 | + } |
| 230 | + |
| 231 | + testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand { |
| 232 | + return helpers.Command("run", "-d", "--name", data.Identifier(), |
| 233 | + "-v", data.Temp().Dir()+`:C:\.`, testutil.CommonImage) |
| 234 | + } |
| 235 | + |
| 236 | + testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected { |
| 237 | + return &test.Expected{ |
| 238 | + ExitCode: expect.ExitCodeGenericFail, |
| 239 | + Errors: []error{errors.New("destination path (c:\\\\) cannot be 'c:' or 'c:\\\\'")}, |
| 240 | + Output: func(stdout string, t tig.T) { |
| 241 | + psOutput := helpers.Capture("ps", "-a", "--format", "{{.Names}}") |
| 242 | + assert.Assert(t, !strings.Contains(psOutput, data.Identifier()), |
| 243 | + "no container should be created when the volume destination is the drive root") |
| 244 | + }, |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + testCase.Run(t) |
| 249 | +} |
0 commit comments