in avro/src/schema.rs [2813:2886]
fn avro_rs_104_test_root_union_of_records() -> TestResult {
// A and B are the same except the name.
let schema_str_a = r#"{
"name": "A",
"type": "record",
"fields": [
{"name": "field_one", "type": "float"}
]
}"#;
let schema_str_b = r#"{
"name": "B",
"type": "record",
"fields": [
{"name": "field_one", "type": "float"}
]
}"#;
let schema_str_c = r#"["A", "B"]"#;
let (schema_c, schemata) =
Schema::parse_str_with_list(schema_str_c, &[schema_str_a, schema_str_b])?;
let schema_a_expected = Schema::Record(RecordSchema {
name: Name::new("A")?,
aliases: None,
doc: None,
fields: vec![RecordField {
name: "field_one".to_string(),
doc: None,
default: None,
aliases: None,
schema: Schema::Float,
order: RecordFieldOrder::Ignore,
position: 0,
custom_attributes: Default::default(),
}],
lookup: BTreeMap::from_iter(vec![("field_one".to_string(), 0)]),
attributes: Default::default(),
});
let schema_b_expected = Schema::Record(RecordSchema {
name: Name::new("B")?,
aliases: None,
doc: None,
fields: vec![RecordField {
name: "field_one".to_string(),
doc: None,
default: None,
aliases: None,
schema: Schema::Float,
order: RecordFieldOrder::Ignore,
position: 0,
custom_attributes: Default::default(),
}],
lookup: BTreeMap::from_iter(vec![("field_one".to_string(), 0)]),
attributes: Default::default(),
});
let schema_c_expected = Schema::Union(UnionSchema::new(vec![
Schema::Ref {
name: Name::new("A")?,
},
Schema::Ref {
name: Name::new("B")?,
},
])?);
assert_eq!(schema_c, schema_c_expected);
assert_eq!(schemata[0], schema_a_expected);
assert_eq!(schemata[1], schema_b_expected);
Ok(())
}