It looks like the error returned by Windows changed in Windows 2025; before
Windows 2025, this produced a `ERROR_INVALID_NAME`;
The filename, directory name, or volume label syntax is incorrect.
But Windows 2025 produces a `ERROR_DIRECTORY` ("The directory name is invalid."):
CreateFile \\\\?\\Volume{d9f06b05-0405-418b-b3e5-4fede64f3cdc}\\windows\\system32\\drivers\\etc\\hosts\\: The directory name is invalid.
Docs; https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -34,6 +34,8 @@ func TestCopyFromContainerPathDoesNotExist(t *testing.T) {
|
| 34 | 34 |
assert.Check(t, is.ErrorContains(err, "Could not find the file /dne in container "+cid)) |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
+// TestCopyFromContainerPathIsNotDir tests that an error is returned when |
|
| 38 |
+// trying to create a directory on a path that's a file. |
|
| 37 | 39 |
func TestCopyFromContainerPathIsNotDir(t *testing.T) {
|
| 38 | 40 |
skip.If(t, testEnv.UsingSnapshotter(), "FIXME: https://github.com/moby/moby/issues/47107") |
| 39 | 41 |
ctx := setupTest(t) |
| ... | ... |
@@ -41,14 +43,29 @@ func TestCopyFromContainerPathIsNotDir(t *testing.T) {
|
| 41 | 41 |
apiClient := testEnv.APIClient() |
| 42 | 42 |
cid := container.Create(ctx, t, apiClient) |
| 43 | 43 |
|
| 44 |
- path := "/etc/passwd/" |
|
| 45 |
- expected := "not a directory" |
|
| 44 |
+ // Pick a path that already exists as a file; on Linux "/etc/passwd" |
|
| 45 |
+ // is expected to be there, so we pick that for convenience. |
|
| 46 |
+ existingFile := "/etc/passwd/" |
|
| 47 |
+ expected := []string{"not a directory"}
|
|
| 46 | 48 |
if testEnv.DaemonInfo.OSType == "windows" {
|
| 47 |
- path = "c:/windows/system32/drivers/etc/hosts/" |
|
| 48 |
- expected = "The filename, directory name, or volume label syntax is incorrect." |
|
| 49 |
+ existingFile = "c:/windows/system32/drivers/etc/hosts/" |
|
| 50 |
+ |
|
| 51 |
+ // Depending on the version of Windows, this produces a "ERROR_INVALID_NAME" (Windows < 2025), |
|
| 52 |
+ // or a "ERROR_DIRECTORY" (Windows 2025); https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- |
|
| 53 |
+ expected = []string{
|
|
| 54 |
+ "The directory name is invalid.", // ERROR_DIRECTORY |
|
| 55 |
+ "The filename, directory name, or volume label syntax is incorrect.", // ERROR_INVALID_NAME |
|
| 56 |
+ } |
|
| 57 |
+ } |
|
| 58 |
+ _, _, err := apiClient.CopyFromContainer(ctx, cid, existingFile) |
|
| 59 |
+ var found bool |
|
| 60 |
+ for _, expErr := range expected {
|
|
| 61 |
+ if err != nil && strings.Contains(err.Error(), expErr) {
|
|
| 62 |
+ found = true |
|
| 63 |
+ break |
|
| 64 |
+ } |
|
| 49 | 65 |
} |
| 50 |
- _, _, err := apiClient.CopyFromContainer(ctx, cid, path) |
|
| 51 |
- assert.ErrorContains(t, err, expected) |
|
| 66 |
+ assert.Check(t, found, "Expected error to be one of %v, but got %v", expected, err) |
|
| 52 | 67 |
} |
| 53 | 68 |
|
| 54 | 69 |
func TestCopyToContainerPathDoesNotExist(t *testing.T) {
|