Skip to content

Commit

Permalink
AVRO-3881: [rust] Writer should write user metadata even if the body …
Browse files Browse the repository at this point in the history
…is empty (#2545)

* writer should write user metadata even if the body is empty

* AVRO-3881: Give a better name to a new test case

---------

Co-authored-by: Martin Grigorov <[email protected]>
  • Loading branch information
nooberfsh and martin-g authored Oct 10, 2023
1 parent c91b887 commit 4d1ac46
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lang/rust/avro/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ impl<'a, W: Write> Writer<'a, W> {
/// **NOTE** This function forces the written data to be flushed (an implicit
/// call to [`flush`](struct.Writer.html#method.flush) is performed).
pub fn into_inner(mut self) -> AvroResult<W> {
self.maybe_write_header()?;
self.flush()?;
Ok(self.writer)
}
Expand Down Expand Up @@ -635,6 +636,7 @@ mod tests {
schema::{DecimalSchema, FixedSchema, Name},
types::Record,
util::zig_i64,
Reader,
};
use pretty_assertions::assert_eq;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -1139,6 +1141,22 @@ mod tests {
Ok(())
}

#[test]
fn test_avro_3881_metadata_empty_body() -> TestResult {
let schema = Schema::parse_str(SCHEMA)?;
let mut writer = Writer::new(&schema, Vec::new());
writer.add_user_metadata("a".to_string(), "b")?;
let result = writer.into_inner()?;

let reader = Reader::with_schema(&schema, &result[..])?;
let mut expected = HashMap::new();
expected.insert("a".to_string(), vec![b'b']);
assert_eq!(reader.user_metadata(), &expected);
assert_eq!(reader.into_iter().count(), 0);

Ok(())
}

#[test]
fn test_avro_3405_writer_add_metadata_failure() -> TestResult {
let schema = Schema::parse_str(SCHEMA)?;
Expand Down

0 comments on commit 4d1ac46

Please sign in to comment.