martin-g commented on code in PR #542:
URL: https://github.com/apache/avro-rs/pull/542#discussion_r3186290354
##########
avro/src/types.rs:
##########
@@ -3494,4 +3502,92 @@ Field with name '"b"' is not a member of the map items"#,
"JSON number 18446744073709551615 could not be converted into an
Avro value as it's too large"
);
}
+
+ #[test]
+ fn avro_rs_test_biggger_string_to_smaller_fixed_resolution() -> TestResult{
+ let schema = Schema::parse_str(r#"
+ {
+ "name": "test",
+ "type": "record",
+ "fields": [{
+ "name": "test_field",
+ "type": {
+ "name": "myFixed",
+ "type": "fixed",
+ "size": 2
+ }
+ }]
+ }"#)?;
+
+ let long_string = "This string is too long and won't
fit!!".to_string();
+ let value = Value::Record(vec![("test_field".to_string(),
+ Value::String(long_string.clone()))]);
+
+ assert_eq!(
+ value.resolve(&schema)
+ .expect_err("Expected resolution to fail since string is too large
for the given fixed schema size")
+ .into_details()
+ .to_string(),
+ Details::CompareFixedSizes { size: 2, n: long_string.len()
}.to_string()
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn avro_rs_test_smaller_string_to_bigger_fixed_resolution() -> TestResult{
+ let schema = Schema::parse_str(r#"
+ {
+ "name": "test",
+ "type": "record",
+ "fields": [{
+ "name": "test_field",
+ "type": {
+ "name": "myFixed",
+ "type": "fixed",
+ "size": 6
+ }
+ }]
+ }"#)?;
+
+ let mut value = Value::Record(vec![("test_field".to_string(),
+ Value::String("abc".to_string()))]);
+
+ value = value.resolve(&schema)?;
+
+ assert_eq!(value,
+ Value::Record(vec![("test_field".to_string() , Value::Fixed(6,
vec![97, 98, 99, 0 ,0 , 0]))])
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn avro_rs_test_smaller_string_to_bigger_fixed_resolution_idempotence() ->
TestResult{
+ let schema = Schema::parse_str(r#"
+ {
+ "name": "test",
+ "type": "record",
+ "fields": [{
+ "name": "test_field",
+ "type": {
+ "name": "myFixed",
+ "type": "fixed",
+ "size": 6
+ }
+ }]
+ }"#)?;
+
+ let mut value = Value::Record(vec![("test_field".to_string(),
+ Value::String("abc".to_string()))]);
+
+ value = value.resolve(&schema)?;
+ value = value.resolve(&schema)?;
Review Comment:
```suggestion
```
##########
avro/src/types.rs:
##########
@@ -3494,4 +3502,92 @@ Field with name '"b"' is not a member of the map items"#,
"JSON number 18446744073709551615 could not be converted into an
Avro value as it's too large"
);
}
+
+ #[test]
+ fn avro_rs_test_biggger_string_to_smaller_fixed_resolution() -> TestResult{
+ let schema = Schema::parse_str(r#"
+ {
+ "name": "test",
+ "type": "record",
+ "fields": [{
+ "name": "test_field",
+ "type": {
+ "name": "myFixed",
+ "type": "fixed",
+ "size": 2
+ }
+ }]
+ }"#)?;
+
+ let long_string = "This string is too long and won't
fit!!".to_string();
+ let value = Value::Record(vec![("test_field".to_string(),
+ Value::String(long_string.clone()))]);
+
+ assert_eq!(
+ value.resolve(&schema)
+ .expect_err("Expected resolution to fail since string is too large
for the given fixed schema size")
+ .into_details()
+ .to_string(),
+ Details::CompareFixedSizes { size: 2, n: long_string.len()
}.to_string()
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn avro_rs_test_smaller_string_to_bigger_fixed_resolution() -> TestResult{
+ let schema = Schema::parse_str(r#"
+ {
+ "name": "test",
+ "type": "record",
+ "fields": [{
+ "name": "test_field",
+ "type": {
+ "name": "myFixed",
+ "type": "fixed",
+ "size": 6
+ }
+ }]
+ }"#)?;
+
+ let mut value = Value::Record(vec![("test_field".to_string(),
+ Value::String("abc".to_string()))]);
+
+ value = value.resolve(&schema)?;
+
+ assert_eq!(value,
+ Value::Record(vec![("test_field".to_string() , Value::Fixed(6,
vec![97, 98, 99, 0 ,0 , 0]))])
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn avro_rs_test_smaller_string_to_bigger_fixed_resolution_idempotence() ->
TestResult{
Review Comment:
```suggestion
fn
avro_rs_542_test_smaller_string_to_bigger_fixed_resolution_idempotence() ->
TestResult {
```
##########
avro/src/types.rs:
##########
@@ -3494,4 +3502,92 @@ Field with name '"b"' is not a member of the map items"#,
"JSON number 18446744073709551615 could not be converted into an
Avro value as it's too large"
);
}
+
+ #[test]
+ fn avro_rs_test_biggger_string_to_smaller_fixed_resolution() -> TestResult{
Review Comment:
```suggestion
fn avro_rs_542_test_bigger_string_to_smaller_fixed_resolution() ->
TestResult {
```
##########
avro/src/types.rs:
##########
@@ -3494,4 +3502,92 @@ Field with name '"b"' is not a member of the map items"#,
"JSON number 18446744073709551615 could not be converted into an
Avro value as it's too large"
);
}
+
+ #[test]
+ fn avro_rs_test_biggger_string_to_smaller_fixed_resolution() -> TestResult{
+ let schema = Schema::parse_str(r#"
+ {
+ "name": "test",
+ "type": "record",
+ "fields": [{
+ "name": "test_field",
+ "type": {
+ "name": "myFixed",
+ "type": "fixed",
+ "size": 2
+ }
+ }]
+ }"#)?;
+
+ let long_string = "This string is too long and won't
fit!!".to_string();
+ let value = Value::Record(vec![("test_field".to_string(),
+ Value::String(long_string.clone()))]);
+
+ assert_eq!(
+ value.resolve(&schema)
+ .expect_err("Expected resolution to fail since string is too large
for the given fixed schema size")
+ .into_details()
+ .to_string(),
+ Details::CompareFixedSizes { size: 2, n: long_string.len()
}.to_string()
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn avro_rs_test_smaller_string_to_bigger_fixed_resolution() -> TestResult{
Review Comment:
```suggestion
fn avro_rs_542_test_smaller_string_to_bigger_fixed_resolution() ->
TestResult {
```
--
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]