vsinghal85 commented on code in PR #4117:
URL: https://github.com/apache/gobblin/pull/4117#discussion_r2099409354


##########
gobblin-utility/src/test/java/org/apache/gobblin/util/HadoopUtilsTest.java:
##########
@@ -333,4 +344,166 @@ public void testMoveToTrash() throws IOException {
     Assert.assertFalse(fs.exists(hadoopUtilsTestDir));
     Assert.assertTrue(fs.exists(trashPath));
   }
+
+  @Test
+  public void testEnsureDirectoryExistsWithAclPreservation() throws Exception {
+    final Path testDir = new Path(new Path(TEST_DIR_PATH), 
"HadoopUtilsTestDir");
+    FileSystem fs = Mockito.mock(FileSystem.class);
+    Path targetDir = new Path(testDir, "target");
+
+    Mockito.when(fs.exists(targetDir)).thenReturn(false);
+    Mockito.when(fs.exists(targetDir.getParent())).thenReturn(true);
+
+    // Create ACL entries
+    List<AclEntry> aclEntries = Lists.newArrayList(
+        new AclEntry.Builder()
+            .setName("user1")
+            .setType(AclEntryType.USER)
+            .setScope(AclEntryScope.ACCESS)
+            .setPermission(FsAction.ALL)
+            .build(),
+        new AclEntry.Builder()
+            .setName("group1")
+            .setType(AclEntryType.GROUP)
+            .setScope(AclEntryScope.ACCESS)
+            .setPermission(FsAction.READ_EXECUTE)
+            .build()
+    );
+
+    // Create OwnerAndPermission with the ACLs
+    OwnerAndPermission ownerAndPermission = 
getOwnerAndPermissionForAclEntries(aclEntries);
+
+    // Mock mkdirs to return true
+    Mockito.when(fs.mkdirs(targetDir)).thenReturn(true);
+    // Call ensureDirectoryExists with copyOnlySourceAclToDest=true
+    HadoopUtils.ensureDirectoryExists(fs, targetDir,
+        Collections.singletonList(ownerAndPermission).listIterator(),
+        true, true);
+    // Verify mkdirs was called
+    Mockito.verify(fs).mkdirs(targetDir);
+    Mockito.verify(fs).removeAcl(targetDir);
+    // Verify modifyAclEntries was called with correct ACLs
+    Mockito.verify(fs).modifyAclEntries(targetDir, aclEntries);
+  }
+
+  @Test
+  public void testEnsureDirectoryExistsWithExistingDirectory() throws 
Exception {
+    final Path testDir = new Path(new Path(TEST_DIR_PATH), 
TEST_CHILD_DIR_NAME);
+    FileSystem fs = Mockito.mock(FileSystem.class);
+    // Create target directory path
+    Path targetDir = new Path(testDir, "target");
+
+    Mockito.when(fs.exists(targetDir)).thenReturn(true);
+    Mockito.when(fs.exists(targetDir.getParent())).thenReturn(true);

Review Comment:
   I prefer it this way, since this is more readable, combining in one line 
would be over optimization here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to