amogh-jahagirdar commented on code in PR #4071:
URL: https://github.com/apache/iceberg/pull/4071#discussion_r847941416


##########
core/src/test/java/org/apache/iceberg/TestSnapshotManager.java:
##########
@@ -250,4 +248,305 @@ public void testCherryPickOverwrite() {
         lastSnapshotId, table.currentSnapshot().snapshotId());
     validateTableFiles(table, FILE_A, FILE_B);
   }
+
+  @Test
+  public void testCreateBranch() {
+    table.newAppend()
+        .appendFile(FILE_A)
+        .commit();
+    long snapshotId = table.currentSnapshot().snapshotId();
+    // Test a basic case of creating a branch
+    table.manageSnapshots()
+        .createBranch("branch1", snapshotId)
+        .commit();
+    SnapshotRef expectedBranch = table.ops().refresh().ref("branch1");
+    Assert.assertTrue(expectedBranch != null &&
+            
expectedBranch.equals(SnapshotRef.branchBuilder(snapshotId).build()));
+
+    // Trying to create a branch with an existing name should fail
+    AssertHelpers.assertThrows("Should fail validation check if we try and 
create branch again",
+        IllegalArgumentException.class, "Ref branch1 already exists",
+        () -> table.manageSnapshots().createBranch("branch1", 
snapshotId).commit());
+
+    // Trying to create another branch within the same chain
+    AssertHelpers.assertThrows("Should fail validation check if we try and 
create branch again",
+        IllegalArgumentException.class, "Ref branch2 already exists",
+        () -> table.manageSnapshots().createBranch("branch2", 
snapshotId).createBranch("branch2", snapshotId).commit());
+  }
+
+
+  @Test
+  public void testCreateTag() {
+    table.newAppend()
+        .appendFile(FILE_A)
+        .commit();
+    long snapshotId = table.currentSnapshot().snapshotId();
+    // Test a basic case of creating a tag
+    table.manageSnapshots()
+        .createTag("tag1", snapshotId)
+        .commit();
+    SnapshotRef expectedTag = table.ops().refresh().ref("tag1");
+
+    Assert.assertTrue(expectedTag != null &&
+        expectedTag.equals(SnapshotRef.tagBuilder(snapshotId).build()));
+
+    // Trying to create a tag with an existing name should fail
+    AssertHelpers.assertThrows("Should fail validation check if we try and 
create tag again",
+        IllegalArgumentException.class, "Ref tag1 already exists",
+        () -> table.manageSnapshots().createTag("tag1", snapshotId).commit());
+
+    // Trying to create another tag within the same chain
+    AssertHelpers.assertThrows("Should fail validation check if we try and 
create tag again",
+        IllegalArgumentException.class, "Ref tag2 already exists",

Review Comment:
   Great point. The issue was the error message `Tag <name> already exists` is 
a bit misleading because references exist in the same namespace. So it's not 
guaranteed that <name> is a tag, it could be a branch. We would have to include 
the type in the error message if we want to go down that route. I'm good with 
that 



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