From bb012f33bec9493cb52fe8dee524f17809c2f5ac Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 2 Sep 2024 14:25:43 +0200 Subject: [PATCH] test(common-utils): Add a test for deleting read-only files Signed-off-by: Sebastian Schuberth --- utils/common/src/test/kotlin/ExtensionsTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/utils/common/src/test/kotlin/ExtensionsTest.kt b/utils/common/src/test/kotlin/ExtensionsTest.kt index 6a3f5d7385365..08c0d61d6801a 100644 --- a/utils/common/src/test/kotlin/ExtensionsTest.kt +++ b/utils/common/src/test/kotlin/ExtensionsTest.kt @@ -99,6 +99,23 @@ class ExtensionsTest : WordSpec({ } } + "File.safeDeleteRecursively()" should { + "be able to delete files that are not writable" { + val dir = tempdir().apply { + resolve("read-only.txt").apply { + writeText("Hello!") + check(setWritable(false)) + } + } + + shouldNotThrow { + dir.safeDeleteRecursively(force = true) + } + + dir.exists() shouldBe false + } + } + "File.expandTilde()" should { "expand the path if the SHELL environment variable is set".config(enabled = Os.env["SHELL"] != null) { File("~/Desktop").expandTilde() shouldBe Os.userHomeDirectory.resolve("Desktop")