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 2022/07/21 12:22:54 UTC

[avro] branch branch-1.11 updated: Avro 3584 rust unit test (#1775)

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 fe5f2f079 Avro 3584 rust unit test (#1775)
fe5f2f079 is described below

commit fe5f2f07917053a5bbf4c9527b6e751e72bb05c6
Author: clesaec <51...@users.noreply.github.com>
AuthorDate: Thu Jul 21 14:22:07 2022 +0200

    Avro 3584 rust unit test (#1775)
    
    AVRO-3584 : add unit test for recursion type
    (cherry picked from commit 18c9b4afb53f6216eca1fb464afaa1082781bf11)
---
 lang/rust/avro/src/schema.rs | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index d8719932d..d8759fd7d 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -2030,6 +2030,39 @@ mod tests {
         assert_eq!(schema_c, schema_c_expected);
     }
 
+    // AVRO-3584 : recursion in type definitions
+    #[test]
+    fn avro_3584_test_recursion_records() {
+        // A and B are the same except the name.
+        let schema_str_a = r#"{
+            "name": "A",
+            "type": "record",
+            "fields": [ {"name": "field_one", "type": "B"} ]
+        }"#;
+
+        let schema_str_b = r#"{
+            "name": "B",
+            "type": "record",
+            "fields": [ {"name": "field_one", "type": "A"} ]
+        }"#;
+
+        let list = Schema::parse_list(&[schema_str_a, schema_str_b]).unwrap();
+
+        let schema_a = list.first().unwrap().clone();
+
+        match schema_a {
+            Schema::Record { fields, .. } => {
+                let f1 = fields.get(0);
+
+                let ref_schema = Schema::Ref {
+                    name: Name::new("B").unwrap(),
+                };
+                assert_eq!(ref_schema, f1.unwrap().schema);
+            }
+            _ => panic!("Expected a record schema!"),
+        }
+    }
+
     // AVRO-3248
     #[test]
     fn test_nullable_record() {