You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2023/04/11 10:57:59 UTC

[avro] branch branch-1.11 updated: AVRO-3735: Add a unit test (#2184)

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

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 15eeb8552 AVRO-3735: Add a unit test (#2184)
15eeb8552 is described below

commit 15eeb8552d5a1c5cb8618202773baf01c314f415
Author: Martin Grigorov <ma...@users.noreply.github.com>
AuthorDate: Tue Apr 11 13:56:50 2023 +0300

    AVRO-3735: Add a unit test (#2184)
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    (cherry picked from commit fc39d86b7930b5c3d4a79bfcd10f659960f94564)
---
 lang/rust/avro/src/schema.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index 15c0d729c..5712784b8 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -4333,4 +4333,68 @@ mod tests {
             panic!("Expected a record schema!");
         }
     }
+
+    #[test]
+    fn avro_3735_parse_enum_namespace() {
+        let schema = r#"
+        {
+            "type": "record",
+            "name": "Foo",
+            "namespace": "name.space",
+            "fields":
+            [
+                {
+                    "name": "barInit",
+                    "type":
+                    {
+                        "type": "enum",
+                        "name": "Bar",
+                        "symbols":
+                        [
+                            "bar0",
+                            "bar1"
+                        ]
+                    }
+                },
+                {
+                    "name": "barUse",
+                    "type": "Bar"
+                }
+            ]
+        } 
+        "#;
+
+        #[derive(
+            Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone, serde::Deserialize, serde::Serialize,
+        )]
+        pub enum Bar {
+            #[serde(rename = "bar0")]
+            Bar0,
+            #[serde(rename = "bar1")]
+            Bar1,
+        }
+
+        #[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize)]
+        pub struct Foo {
+            #[serde(rename = "barInit")]
+            pub bar_init: Bar,
+            #[serde(rename = "barUse")]
+            pub bar_use: Bar,
+        }
+
+        let schema = Schema::parse_str(schema).unwrap();
+
+        let foo = Foo {
+            bar_init: Bar::Bar0,
+            bar_use: Bar::Bar1,
+        };
+
+        let avro_value = crate::to_value(foo).unwrap();
+        assert!(avro_value.validate(&schema));
+
+        let mut writer = crate::Writer::new(&schema, Vec::new());
+
+        // schema validation happens here
+        writer.append(avro_value).unwrap();
+    }
 }