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 2023/04/11 10:57:02 UTC
[avro] branch master updated: AVRO-3735: Add a unit test (#2184)
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new fc39d86b7 AVRO-3735: Add a unit test (#2184)
fc39d86b7 is described below
commit fc39d86b7930b5c3d4a79bfcd10f659960f94564
Author: Martin Grigorov <ma...@users.noreply.github.com>
AuthorDate: Tue Apr 11 13:56:50 2023 +0300
AVRO-3735: Add a unit test (#2184)
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
lang/rust/avro/src/schema.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index 07f2ac3ac..1289aa101 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -4369,4 +4369,68 @@ mod tests {
panic!("Expected a record schema!");
}
}
+
+ #[test]
+ fn avro_3735_parse_enum_namespace() {
+ let schema = r#"
+ {
+ "type": "record",
+ "name": "Foo",
+ "namespace": "name.space",
+ "fields":
+ [
+ {
+ "name": "barInit",
+ "type":
+ {
+ "type": "enum",
+ "name": "Bar",
+ "symbols":
+ [
+ "bar0",
+ "bar1"
+ ]
+ }
+ },
+ {
+ "name": "barUse",
+ "type": "Bar"
+ }
+ ]
+ }
+ "#;
+
+ #[derive(
+ Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone, serde::Deserialize, serde::Serialize,
+ )]
+ pub enum Bar {
+ #[serde(rename = "bar0")]
+ Bar0,
+ #[serde(rename = "bar1")]
+ Bar1,
+ }
+
+ #[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize)]
+ pub struct Foo {
+ #[serde(rename = "barInit")]
+ pub bar_init: Bar,
+ #[serde(rename = "barUse")]
+ pub bar_use: Bar,
+ }
+
+ let schema = Schema::parse_str(schema).unwrap();
+
+ let foo = Foo {
+ bar_init: Bar::Bar0,
+ bar_use: Bar::Bar1,
+ };
+
+ let avro_value = crate::to_value(foo).unwrap();
+ assert!(avro_value.validate(&schema));
+
+ let mut writer = crate::Writer::new(&schema, Vec::new());
+
+ // schema validation happens here
+ writer.append(avro_value).unwrap();
+ }
}