From 20bf697ba6fd2aa769342c8a3b343ae265e46330 Mon Sep 17 00:00:00 2001 From: Florian Schwalm <68847951+egfx-notifications@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:24:10 +0100 Subject: chore(cli): Fix rename test for XFS (#21215) Renaming a directory to a path where a non-empty directory already exists was asserted to always fail with `ENOTEMPTY` According to glibc manual the function may also fail with `EEXIST` on "some other systems". One such case is using XFS [^1]. This commit handles the EEXIST case. [^1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/xfs/xfs_inode.c?h=v4.18&id=94710cac0ef4ee177a63b5227664b38c95bbf703#n3082 --- cli/tests/unit/rename_test.ts | 25 ++++++++++++++++++------- cli/tests/unit/test_util.ts | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'cli') diff --git a/cli/tests/unit/rename_test.ts b/cli/tests/unit/rename_test.ts index 94603a601..cdc5d98a0 100644 --- a/cli/tests/unit/rename_test.ts +++ b/cli/tests/unit/rename_test.ts @@ -2,6 +2,8 @@ import { assert, assertEquals, + AssertionError, + assertIsError, assertThrows, pathToAbsoluteFileUrl, } from "./test_util.ts"; @@ -149,13 +151,22 @@ Deno.test( Error, "Is a directory", ); - assertThrows( - () => { - Deno.renameSync(olddir, fulldir); - }, - Error, - "Directory not empty", - ); + try { + assertThrows( + () => { + Deno.renameSync(olddir, fulldir); + }, + Error, + "Directory not empty", + ); + } catch (e) { + // rename syscall may also return EEXIST, e.g. with XFS + assertIsError( + e, + AssertionError, + `Expected error message to include "Directory not empty", but got "File exists`, + ); + } assertThrows( () => { Deno.renameSync(olddir, file); diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index de1e8e8c5..ccc8f51a1 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -8,6 +8,7 @@ export { assertEquals, assertFalse, AssertionError, + assertIsError, assertMatch, assertNotEquals, assertNotStrictEquals, -- cgit v1.2.3