Skip to content

Commit

Permalink
AVRO-3894: [Rust] Add a unit test for schema_compatibility
Browse files Browse the repository at this point in the history
Provided-by: Josua Stingelin

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g committed Oct 25, 2023
1 parent 0c9db11 commit 35033d7
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lang/rust/avro/src/schema_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,4 +1038,49 @@ mod tests {

Ok(())
}

#[test]
fn avro_3894_take_aliases_into_account_when_serializing_for_schema_compatibility() -> TestResult
{
use serde::{Deserialize, Serialize};

const RAW_SCHEMA_V1: &str = r#"
{
"type": "record",
"name": "Conference",
"namespace": "advdaba",
"fields": [
{"type": "string", "name": "name"},
{"type": "long", "name": "date"}
]
}"#;
const RAW_SCHEMA_V2: &str = r#"
{
"type": "record",
"name": "Conference",
"namespace": "advdaba",
"fields": [
{"type": "string", "name": "name"},
{"type": "long", "name": "date", "aliases" : [ "time" ]}
]
}"#;

#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
pub struct Conference {
pub name: String,
pub date: i64,
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
pub struct ConferenceV2 {
pub name: String,
pub time: i64,
}

let schema_v1 = Schema::parse_str(RAW_SCHEMA_V1)?;
let schema_v2 = Schema::parse_str(RAW_SCHEMA_V2)?;

assert!(SchemaCompatibility::can_read(&schema_v1, &schema_v2));

Ok(())
}
}

0 comments on commit 35033d7

Please sign in to comment.