martin-g commented on code in PR #362:
URL: https://github.com/apache/avro-rs/pull/362#discussion_r2605401715


##########
avro/tests/schema.rs:
##########
@@ -708,39 +708,41 @@ fn test_doc_attributes() -> TestResult {
     Ok(())
 }
 
-/*
-TODO: (#94) add support for user-defined attributes and uncomment (may need 
some tweaks to compile)
+// https://github.com/flavray/avro-rs/issues/93
 #[test]
-fn test_other_attributes() {
-    fn assert_attribute_type(attribute: (String, serde_json::Value)) {
-        match attribute.1.as_ref() {
-            "cp_boolean" => assert!(attribute.2.is_bool()),
-            "cp_int" => assert!(attribute.2.is_i64()),
-            "cp_object" => assert!(attribute.2.is_object()),
-            "cp_float" => assert!(attribute.2.is_f64()),
-            "cp_array" => assert!(attribute.2.is_array()),
+fn test_avro_old_93_other_attributes() -> TestResult {
+    fn assert_attribute_type(attribute: (&String, &serde_json::Value)) {
+        match attribute.0.as_str() {
+            "cp_boolean" => assert!(attribute.1.is_boolean()),
+            "cp_int" => assert!(attribute.1.is_i64()),
+            "cp_object" => assert!(attribute.1.is_object()),
+            "cp_float" => assert!(attribute.1.is_f64()),
+            "cp_array" => assert!(attribute.1.is_array()),
+            "cp_string" => assert!(attribute.1.is_string()),
+            "cp_null" => assert!(attribute.1.is_null()),
+            _ => panic!("Unexpected attribute name: {attribute:?}"),
         }
     }
 
     for (raw_schema, _) in OTHER_ATTRIBUTES_EXAMPLES.iter() {
         let schema = Schema::parse_str(raw_schema)?;
         // all inputs have at least some user-defined attributes
-        assert!(schema.other_attributes.is_some());
-        for prop in schema.other_attributes?.iter() {
+        assert!(schema.custom_attributes().is_some());
+        for prop in schema.custom_attributes().unwrap().iter() {
             assert_attribute_type(prop);
         }
-        if let Schema::Record { fields, .. } = schema {
-           for f in fields {
-               // all fields in the record have at least some user-defined 
attributes
-               assert!(f.schema.other_attributes.is_some());
-               for prop in f.schema.other_attributes?.iter() {
-                   assert_attribute_type(prop);
-               }
-           }
+        if let Schema::Record(RecordSchema { fields, .. }) = schema {
+            for f in fields {
+                // all fields in the record have at least some user-defined 
attributes
+                assert!(f.schema.custom_attributes().is_some());

Review Comment:
   Here you use the schema's attributes, not the field's attributes.
   Those are already verified at 
https://github.com/apache/avro-rs/pull/362/files#diff-4f38d574bfee56e26d21afb16dd9f0fc3d2554436da429f1e4facea752e15ffdR730-R732



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

Reply via email to