From bcfc6d954dc6e18f5c8d9e207d7827dff49a043c Mon Sep 17 00:00:00 2001 From: Marvin Date: Sun, 9 Jul 2023 17:29:03 +0200 Subject: [PATCH] feat: add test methods for the newly added method to delete directories from templates. --- .../modules/s3/S3TemplateStorageTest.java | 11 +++++++++++ .../modules/sftp/SFTPTemplateStorage.java | 1 - .../modules/sftp/SFTPTemplateStorageTest.java | 11 +++++++++++ .../node/template/LocalTemplateStorageTest.java | 11 +++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/storage-s3/src/test/java/eu/cloudnetservice/modules/s3/S3TemplateStorageTest.java b/modules/storage-s3/src/test/java/eu/cloudnetservice/modules/s3/S3TemplateStorageTest.java index 19344d3fbb..cc95083130 100644 --- a/modules/storage-s3/src/test/java/eu/cloudnetservice/modules/s3/S3TemplateStorageTest.java +++ b/modules/storage-s3/src/test/java/eu/cloudnetservice/modules/s3/S3TemplateStorageTest.java @@ -201,4 +201,15 @@ void testTemplateDelete() { Assertions.assertFalse(storage.contains(TEMPLATE)); Assertions.assertFalse(storage.hasFile(TEMPLATE, "test.txt")); } + + @Test + @Order(120) + void testDeleteDirectory() { + var directory = "hello"; + Assertions.assertTrue(storage.createDirectory(TEMPLATE, directory)); + Assertions.assertTrue(storage.createFile(TEMPLATE, directory + "/test.txt")); + Assertions.assertTrue(storage.hasFile(TEMPLATE, directory + "/test.txt")); + Assertions.assertTrue(storage.deleteDirectory(TEMPLATE, directory)); + Assertions.assertFalse(storage.hasFile(TEMPLATE, directory + "/test.txt")); + } } diff --git a/modules/storage-sftp/src/main/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorage.java b/modules/storage-sftp/src/main/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorage.java index 08612079d7..83fa98cd97 100644 --- a/modules/storage-sftp/src/main/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorage.java +++ b/modules/storage-sftp/src/main/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorage.java @@ -277,7 +277,6 @@ public boolean deleteFile(@NonNull ServiceTemplate template, @NonNull String pat public boolean deleteDirectory(@NonNull ServiceTemplate template, @NonNull String path) { return this.executeWithClient(client -> { this.deleteDir(client, this.constructRemotePath(template, path)); - client.rmdir(this.constructRemotePath(template, path)); return true; }, false); } diff --git a/modules/storage-sftp/src/test/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorageTest.java b/modules/storage-sftp/src/test/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorageTest.java index c7aad15f4a..a7d394388d 100644 --- a/modules/storage-sftp/src/test/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorageTest.java +++ b/modules/storage-sftp/src/test/java/eu/cloudnetservice/modules/sftp/SFTPTemplateStorageTest.java @@ -193,4 +193,15 @@ void testTemplateDelete() { Assertions.assertFalse(storage.contains(TEMPLATE)); Assertions.assertFalse(storage.hasFile(TEMPLATE, "test.txt")); } + + @Test + @Order(120) + void testDeleteDirectory() { + var directory = "hello"; + Assertions.assertTrue(storage.createDirectory(TEMPLATE, directory)); + Assertions.assertTrue(storage.createFile(TEMPLATE, directory + "/test.txt")); + Assertions.assertTrue(storage.hasFile(TEMPLATE, directory + "/test.txt")); + Assertions.assertTrue(storage.deleteDirectory(TEMPLATE, directory)); + Assertions.assertFalse(storage.hasFile(TEMPLATE, directory + "/test.txt")); + } } diff --git a/node/src/test/java/eu/cloudnetservice/node/template/LocalTemplateStorageTest.java b/node/src/test/java/eu/cloudnetservice/node/template/LocalTemplateStorageTest.java index 6904911f7c..0f41ea5f3c 100644 --- a/node/src/test/java/eu/cloudnetservice/node/template/LocalTemplateStorageTest.java +++ b/node/src/test/java/eu/cloudnetservice/node/template/LocalTemplateStorageTest.java @@ -177,4 +177,15 @@ void testTemplateDelete() { Assertions.assertFalse(storage.contains(TEMPLATE)); Assertions.assertFalse(storage.hasFile(TEMPLATE, "test.txt")); } + + @Test + @Order(120) + void testDeleteDirectory() { + var directory = "hello"; + Assertions.assertTrue(storage.createDirectory(TEMPLATE, directory)); + Assertions.assertTrue(storage.createFile(TEMPLATE, directory + "/test.txt")); + Assertions.assertTrue(storage.hasFile(TEMPLATE, directory + "/test.txt")); + Assertions.assertTrue(storage.deleteDirectory(TEMPLATE, directory)); + Assertions.assertFalse(storage.hasFile(TEMPLATE, directory + "/test.txt")); + } }