You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/11/18 12:58:24 UTC

[GitHub] [avro] martin-g commented on a diff in pull request #1971: AVRO-3674: [Rust] Pass the correct enclosing namespace when validating and resolving

martin-g commented on code in PR #1971:
URL: https://github.com/apache/avro/pull/1971#discussion_r1026404700


##########
lang/rust/avro/src/types.rs:
##########
@@ -2391,4 +2442,150 @@ Field with name '"b"' is not a member of the map items"#,
             "field b record is invalid against the schema"
         ); // this should pass, but doesn't
     }
+
+    #[test]
+    fn test_avro_3674_validate_namespace_resolution() {
+        use crate::ser::Serializer;
+        use serde::Serialize;
+
+        let schema = Schema::parse_str(
+            r#"{
+            "type": "record",
+            "name": "NamespacedMessage",
+            "namespace": "com.domain",
+            "fields": [
+                {
+                    "type": "record",
+                    "name": "field_a",
+                    "fields": [
+                        {
+                            "name": "enum_a",
+                            "type": {
+                                "type": "enum",
+                                "name": "EnumType",
+                                "symbols": [
+                                    "SYMBOL_1",
+                                    "SYMBOL_2"
+                                ],
+                                "default": "SYMBOL_1"
+                            }
+                        },
+                        {
+                            "name": "enum_b",
+                            "type": "EnumType"
+                        }
+                    ]
+                }
+            ]
+        }"#,
+        )
+        .unwrap();
+
+        #[derive(Serialize)]
+        enum EnumType {
+            #[serde(rename = "SYMBOL_1")]
+            Symbol1,
+            #[serde(rename = "SYMBOL_2")]
+            Symbol2,
+        }
+
+        #[derive(Serialize)]
+        struct FieldA {
+            enum_a: EnumType,
+            enum_b: EnumType,
+        }
+
+        #[derive(Serialize)]
+        struct NamespacedMessage {
+            field_a: FieldA,
+        }
+
+        let msg = NamespacedMessage {
+            field_a: FieldA {
+                enum_a: EnumType::Symbol2,
+                enum_b: EnumType::Symbol1,
+            },
+        };
+
+        let mut ser = Serializer::default();
+        let test_value: Value = msg.serialize(&mut ser).unwrap();
+        assert!(test_value.validate(&schema), "test_value should validate");
+        assert!(
+            test_value.resolve(&schema).is_ok(),
+            "test_value should resolve"
+        );
+    }
+
+    #[test]
+    fn test_avro_3674_validate_no_namespace_resolution() {

Review Comment:
   I may do it in a separate PR!
   I want to do some cleanup to the `_internal` methods too.



-- 
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: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org