martin-g commented on a change in pull request #1379:
URL: https://github.com/apache/avro/pull/1379#discussion_r737182833



##########
File path: lang/rust/src/reader.rs
##########
@@ -341,6 +343,40 @@ mod tests {
         6u8, 102u8, 111u8, 111u8, 84u8, 6u8, 98u8, 97u8, 114u8, 94u8, 61u8, 
54u8, 221u8, 190u8,
         207u8, 108u8, 180u8, 158u8, 57u8, 114u8, 40u8, 173u8, 199u8, 228u8, 
239u8,
     ];
+    const TEST_RECORD_SCHEMA: &str = r#"

Review comment:
       The name of the schema and the struct below are too generic.
   Let's add `_3240` (the JIRA number) to them

##########
File path: lang/rust/src/decode.rs
##########
@@ -23,7 +23,7 @@ use crate::{
     util::{safe_len, zag_i32, zag_i64},
     AvroResult, Error,
 };
-use std::{collections::HashMap, convert::TryFrom, io::Read, str::FromStr};
+use std::{collections::HashMap, convert::TryFrom, io::{ErrorKind,Read}, 
str::FromStr};

Review comment:
       Add an empty space between `ErrorKind` and `Read`.
   I expect clippy to complain once the checks are enabled.

##########
File path: lang/rust/src/reader.rs
##########
@@ -341,6 +343,40 @@ mod tests {
         6u8, 102u8, 111u8, 111u8, 84u8, 6u8, 98u8, 97u8, 114u8, 94u8, 61u8, 
54u8, 221u8, 190u8,
         207u8, 108u8, 180u8, 158u8, 57u8, 114u8, 40u8, 173u8, 199u8, 228u8, 
239u8,
     ];
+    const TEST_RECORD_SCHEMA: &str = r#"
+    {
+      "type": "record",
+      "name": "test",
+      "fields": [
+        {
+          "name": "a",
+          "type": "long",
+          "default": 42
+        },
+        {
+          "name": "b",
+          "type": "string"
+        },
+        {
+            "name": "a_nullable_array",
+            "type": ["null", {"type": "array", "items": {"type": "string"}}],
+            "default": null
+        },
+        {
+            "name": "a_nullable_boolean",
+            "type": ["null", {"type": "boolean"}],
+            "default": null
+        }
+      ]
+    }
+    "#;
+    #[derive(Default, Debug, Deserialize, PartialEq)]

Review comment:
       Is `PartialEq` really needed ?

##########
File path: lang/rust/src/reader.rs
##########
@@ -358,6 +394,23 @@ mod tests {
         );
     }
 
+    #[test]
+    fn test_from_avro_datum_with_union_to_struct() {
+        let schema = Schema::parse_str(TEST_RECORD_SCHEMA).unwrap();
+        let mut encoded: &'static [u8] = &[54, 6, 102, 111, 111];
+
+        let avro_datum = from_avro_datum(&schema, &mut encoded, None).unwrap();
+        let test_record: TestRecord = match &avro_datum {
+            Value::Record(_) => from_value::<TestRecord>(&avro_datum).unwrap(),
+            _ => panic!("could not map avro data to struct"),
+        };
+
+        assert_eq!(
+            test_record.a_nullable_array,
+            None
+        );

Review comment:
       Please add assertions for all record fields.

##########
File path: lang/rust/src/reader.rs
##########
@@ -358,6 +394,23 @@ mod tests {
         );
     }
 
+    #[test]
+    fn test_from_avro_datum_with_union_to_struct() {
+        let schema = Schema::parse_str(TEST_RECORD_SCHEMA).unwrap();
+        let mut encoded: &'static [u8] = &[54, 6, 102, 111, 111];
+
+        let avro_datum = from_avro_datum(&schema, &mut encoded, None).unwrap();
+        let test_record: TestRecord = match &avro_datum {
+            Value::Record(_) => from_value::<TestRecord>(&avro_datum).unwrap(),
+            _ => panic!("could not map avro data to struct"),

Review comment:
       Let's use a proper name instead of `_`, e.g. `unexpected` and print it 
in the panic message. It will help for debugging regressions.




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