tanvipenumudy commented on code in PR #4448:
URL: https://github.com/apache/ozone/pull/4448#discussion_r1155477356


##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectHead.java:
##########
@@ -101,4 +105,64 @@ public void testHeadFailByBadName() throws Exception {
       Assert.assertEquals(HTTP_NOT_FOUND, ex.getHttpCode());
     }
   }
+
+  @Test
+  public void testHeadWhenKeyIsAFileAndKeyPathDoesNotEndWithASlash()
+      throws IOException, OS3Exception {
+    // GIVEN
+    final String keyPath = "keyDir";
+    OzoneConfiguration config = new OzoneConfiguration();
+    config.set(OZONE_S3G_FSO_DIRECTORY_CREATION_ENABLED, "true");
+    keyEndpoint.setOzoneConfiguration(config);
+    String keyContent = "content";
+    OzoneOutputStream out = bucket.createKey(keyPath,
+        keyContent.getBytes(UTF_8).length,
+        ReplicationConfig.fromTypeAndFactor(ReplicationType.RATIS,
+            ReplicationFactor.ONE), new HashMap<>());
+    out.write(keyContent.getBytes(UTF_8));
+    out.close();
+
+    // WHEN
+    final Response response = keyEndpoint.head(bucketName, keyPath);
+
+    // THEN
+    Assertions.assertEquals(HttpStatus.SC_OK, response.getStatus());
+    bucket.deleteKey(keyPath);
+  }
+
+  @Test
+  public void testHeadWhenKeyIsDirectoryAndKeyPathDoesNotEndWithASlash()
+      throws IOException, OS3Exception {
+    // GIVEN
+    final String keyPath = "keyDir";
+    OzoneConfiguration config = new OzoneConfiguration();
+    config.set(OZONE_S3G_FSO_DIRECTORY_CREATION_ENABLED, "true");
+    keyEndpoint.setOzoneConfiguration(config);
+    bucket.createDirectory(keyPath);
+
+    // WHEN
+    final Response response = keyEndpoint.head(bucketName, keyPath);
+
+    // THEN
+    Assertions.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
+    bucket.deleteKey(keyPath);
+  }
+
+  @Test
+  public void testHeadWhenKeyIsDirectoryAndKeyPathEndsWithASlash()
+      throws IOException, OS3Exception {
+    // GIVEN
+    final String keyPath = "keyDir/";
+    OzoneConfiguration config = new OzoneConfiguration();
+    config.set(OZONE_S3G_FSO_DIRECTORY_CREATION_ENABLED, "true");
+    keyEndpoint.setOzoneConfiguration(config);
+    bucket.createDirectory(keyPath);
+
+    // WHEN
+    final Response response = keyEndpoint.head(bucketName, keyPath);
+
+    // THEN
+    Assertions.assertEquals(HttpStatus.SC_OK, response.getStatus());
+    bucket.deleteKey(keyPath);
+  }

Review Comment:
   Could we consider including a test case that verifies the behavior when 
attempting to retrieve metadata for a file using a key path that ends with a 
slash ("/")? The expected behavior is that the request should fail with a 404 
status code since the specified key path does not correspond to a directory.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to