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


##########
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);
+  }
+

Review Comment:
   ```suggestion
     @Test
     public void testHeadWhenKeyIsAFileAndKeyPathEndsWithASlash()
         throws IOException, OS3Exception {
       // GIVEN
       final String keyPath = "keyFile";
       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_NOT_FOUND, response.getStatus());
       bucket.deleteKey(keyPath);
     }
   ```



-- 
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