From 612af8b303a5170dd1f052b484a8e41860cfed7f Mon Sep 17 00:00:00 2001 From: Rik Heijdens Date: Thu, 29 Sep 2022 14:14:35 +0200 Subject: [PATCH] AVRO-3631: Add test for serializing fixed fields This test-case mainly demonstrates the issue reported in AVRO-3631. It is unclear to me whether we should actually expect the serializer to serialize to a Value::Fixed right away given that Schema information is not available at this stage. --- lang/rust/avro/src/ser.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lang/rust/avro/src/ser.rs b/lang/rust/avro/src/ser.rs index 9f05836ab22..aa033f7b6ee 100644 --- a/lang/rust/avro/src/ser.rs +++ b/lang/rust/avro/src/ser.rs @@ -676,6 +676,11 @@ mod tests { Val2(f32, f32, f32), } + #[derive(Debug, Serialize, Deserialize)] + struct TestStructFixedField { + field: [u8; 6], + } + #[test] fn test_to_value() -> TestResult { let test = Test { @@ -1031,4 +1036,18 @@ mod tests { assert!(ser.is_human_readable()); } + + #[test] + fn test_to_value_fixed_field_avro_3631() { + let test = TestStructFixedField { field: [1; 6] }; + let expected = Value::Record(vec![( + "field".to_owned(), + Value::Fixed(6, Vec::from(test.field.clone())), + )]); + assert_eq!( + to_value(test).unwrap(), + expected, + "error serializing fixed array" + ); + } }