martin-g commented on code in PR #2785:
URL: https://github.com/apache/avro/pull/2785#discussion_r1511422833
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
Review Comment:
```suggestion
let schema = crate::Schema::parse_str(schema_content)?;
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "SOZU".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(&data).unwrap();
+
+ let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
value).unwrap());
Review Comment:
```suggestion
let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
value)?);
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "SOZU".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(&data).unwrap();
Review Comment:
```suggestion
let value = crate::to_value(&data)?;
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "SOZU".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(&data).unwrap();
+
+ let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
value).unwrap());
+
+ // decode from avro
+ let value = crate::from_avro_datum(&schema, &mut buf, None).unwrap();
+
+ let decoded_data: StringEnum = crate::from_value(&value).unwrap();
+
+ assert_eq!(decoded_data, data);
+ }
+
+ #[test]
+ fn avro_3955_encode_enum_data_with_wrong_content() {
Review Comment:
```suggestion
fn avro_3955_encode_enum_data_with_wrong_content() -> TestResult {
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "SOZU".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(&data).unwrap();
+
+ let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
value).unwrap());
+
+ // decode from avro
+ let value = crate::from_avro_datum(&schema, &mut buf, None).unwrap();
Review Comment:
```suggestion
let value = crate::from_avro_datum(&schema, &mut buf, None)?;
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "SOZU".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(&data).unwrap();
+
+ let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
value).unwrap());
+
+ // decode from avro
+ let value = crate::from_avro_datum(&schema, &mut buf, None).unwrap();
+
+ let decoded_data: StringEnum = crate::from_value(&value).unwrap();
Review Comment:
```suggestion
let decoded_data: StringEnum = crate::from_value(&value)?;
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
Review Comment:
```suggestion
fn avro_3955_decode_enum() -> TestResult {
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "SOZU".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(&data).unwrap();
+
+ let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
value).unwrap());
+
+ // decode from avro
+ let value = crate::from_avro_datum(&schema, &mut buf, None).unwrap();
+
+ let decoded_data: StringEnum = crate::from_value(&value).unwrap();
+
+ assert_eq!(decoded_data, data);
+ }
+
+ #[test]
+ fn avro_3955_encode_enum_data_with_wrong_content() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "WRONG_ITEM".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(data).unwrap();
Review Comment:
```suggestion
let value = crate::to_value(data)?;
```
##########
lang/rust/avro/src/de.rs:
##########
@@ -676,6 +676,85 @@ mod tests {
use super::*;
+ #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
+ pub struct StringEnum {
+ pub source: String,
+ }
+
+ #[test]
+ fn avro_3955_decode_enum() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
+ let data = StringEnum {
+ source: "SOZU".to_string(),
+ };
+
+ // encode into avro
+ let value = crate::to_value(&data).unwrap();
+
+ let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
value).unwrap());
+
+ // decode from avro
+ let value = crate::from_avro_datum(&schema, &mut buf, None).unwrap();
+
+ let decoded_data: StringEnum = crate::from_value(&value).unwrap();
+
+ assert_eq!(decoded_data, data);
+ }
+
+ #[test]
+ fn avro_3955_encode_enum_data_with_wrong_content() {
+ let schema_content = r#"
+{
+ "name": "AccessLog",
+ "namespace": "com.clevercloud.accesslogs.common.avro",
+ "type": "record",
+ "fields": [
+ {
+ "name": "source",
+ "type": {
+ "type": "enum",
+ "name": "SourceType",
+ "items": "string",
+ "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
+ }
+ }
+ ]
+}
+"#;
+
+ let schema = crate::Schema::parse_str(schema_content).unwrap();
Review Comment:
```suggestion
let schema = crate::Schema::parse_str(schema_content)?;
```
--
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]