You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by li...@apache.org on 2025/05/26 10:39:46 UTC

(iceberg-rust) branch main updated: test: Add missing tests for update_namespace method in sql catalog (#1373)

This is an automated email from the ASF dual-hosted git repository.

liurenjie1024 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new fbf9b92e test: Add missing tests for update_namespace method in sql catalog (#1373)
fbf9b92e is described below

commit fbf9b92e0a201d1e37d74a568687174eac823539
Author: Ryan <88...@users.noreply.github.com>
AuthorDate: Mon May 26 03:39:40 2025 -0700

    test: Add missing tests for update_namespace method in sql catalog (#1373)
    
    ## Which issue does this PR close?
    
    
    
    - Closes #.
    
    ## What changes are included in this PR?
    
    
    
    Adds tests for the `update_namespace` method in the SQL catalog crate
    that were previously missing.
    
    ## Are these changes tested?
    
    
    :+1:
---
 crates/catalog/sql/src/catalog.rs | 124 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)

diff --git a/crates/catalog/sql/src/catalog.rs b/crates/catalog/sql/src/catalog.rs
index 78767c5b..841c4c1b 100644
--- a/crates/catalog/sql/src/catalog.rs
+++ b/crates/catalog/sql/src/catalog.rs
@@ -1160,6 +1160,130 @@ mod tests {
         );
     }
 
+    #[tokio::test]
+    async fn test_update_namespace_noop() {
+        let warehouse_loc = temp_path();
+        let catalog = new_sql_catalog(warehouse_loc).await;
+        let namespace_ident = NamespaceIdent::new("a".into());
+        create_namespace(&catalog, &namespace_ident).await;
+
+        catalog
+            .update_namespace(&namespace_ident, HashMap::new())
+            .await
+            .unwrap();
+
+        assert_eq!(
+            *catalog
+                .get_namespace(&namespace_ident)
+                .await
+                .unwrap()
+                .properties(),
+            HashMap::from_iter([("exists".to_string(), "true".to_string())])
+        )
+    }
+
+    #[tokio::test]
+    async fn test_update_namespace() {
+        let warehouse_loc = temp_path();
+        let catalog = new_sql_catalog(warehouse_loc).await;
+        let namespace_ident = NamespaceIdent::new("a".into());
+        create_namespace(&catalog, &namespace_ident).await;
+
+        let mut props = HashMap::from_iter([
+            ("prop1".to_string(), "val1".to_string()),
+            ("prop2".into(), "val2".into()),
+        ]);
+
+        catalog
+            .update_namespace(&namespace_ident, props.clone())
+            .await
+            .unwrap();
+
+        props.insert("exists".into(), "true".into());
+
+        assert_eq!(
+            *catalog
+                .get_namespace(&namespace_ident)
+                .await
+                .unwrap()
+                .properties(),
+            props
+        )
+    }
+
+    #[tokio::test]
+    async fn test_update_nested_namespace() {
+        let warehouse_loc = temp_path();
+        let catalog = new_sql_catalog(warehouse_loc).await;
+        let namespace_ident = NamespaceIdent::from_strs(["a", "b"]).unwrap();
+        create_namespace(&catalog, &namespace_ident).await;
+
+        let mut props = HashMap::from_iter([
+            ("prop1".to_string(), "val1".to_string()),
+            ("prop2".into(), "val2".into()),
+        ]);
+
+        catalog
+            .update_namespace(&namespace_ident, props.clone())
+            .await
+            .unwrap();
+
+        props.insert("exists".into(), "true".into());
+
+        assert_eq!(
+            *catalog
+                .get_namespace(&namespace_ident)
+                .await
+                .unwrap()
+                .properties(),
+            props
+        )
+    }
+
+    #[tokio::test]
+    async fn test_update_namespace_errors_if_namespace_doesnt_exist() {
+        let warehouse_loc = temp_path();
+        let catalog = new_sql_catalog(warehouse_loc).await;
+        let namespace_ident = NamespaceIdent::new("a".into());
+
+        let props = HashMap::from_iter([
+            ("prop1".to_string(), "val1".to_string()),
+            ("prop2".into(), "val2".into()),
+        ]);
+
+        let err = catalog
+            .update_namespace(&namespace_ident, props)
+            .await
+            .unwrap_err();
+
+        assert_eq!(
+            err.message(),
+            format!("No such namespace: {:?}", namespace_ident)
+        );
+    }
+
+    #[tokio::test]
+    async fn test_update_namespace_errors_if_nested_namespace_doesnt_exist() {
+        let warehouse_loc = temp_path();
+        let catalog = new_sql_catalog(warehouse_loc).await;
+        let namespace_ident = NamespaceIdent::from_strs(["a", "b"]).unwrap();
+
+        let props = HashMap::from_iter([
+            ("prop1".to_string(), "val1".to_string()),
+            ("prop2".into(), "val2".into()),
+        ]);
+
+        let err = catalog
+            .update_namespace(&namespace_ident, props)
+            .await
+            .unwrap_err();
+
+        assert_eq!(
+            err.message(),
+            format!("No such namespace: {:?}", namespace_ident)
+        );
+    }
+
     #[tokio::test]
     async fn test_drop_namespace() {
         let warehouse_loc = temp_path();