From 5b93b807f1555fb3c88471053340ff92a9b91f36 Mon Sep 17 00:00:00 2001 From: Gerard Klijs Date: Mon, 5 Jul 2021 20:34:53 +0200 Subject: [PATCH] Add test to encode single message when there are multiple messages. --- src/async_impl/proto_raw.rs | 36 ++++++++++++++++++++++++++---------- src/blocking/proto_raw.rs | 35 +++++++++++++++++++++++++---------- test_utils/src/lib.rs | 2 +- 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/async_impl/proto_raw.rs b/src/async_impl/proto_raw.rs index 707aa6a..b25cf03 100644 --- a/src/async_impl/proto_raw.rs +++ b/src/async_impl/proto_raw.rs @@ -190,7 +190,7 @@ mod tests { }; use test_utils::{ get_proto_body, get_proto_body_with_reference, get_proto_complex, - get_proto_complex_proto_test_message, get_proto_complex_proto_test_message_data_only, + get_proto_complex_only_data, get_proto_complex_proto_test_message, get_proto_complex_references, get_proto_hb_101, get_proto_hb_101_only_data, get_proto_hb_schema, get_proto_result, }; @@ -234,16 +234,35 @@ mod tests { SubjectNameStrategy::RecordNameStrategy(String::from("nl.openweb.data.Heartbeat")); let encoded_data = encoder - .encode_single_message( - get_proto_hb_101_only_data(), - strategy, - ) + .encode_single_message(get_proto_hb_101_only_data(), strategy) .await .unwrap(); assert_eq!(encoded_data, get_proto_hb_101()) } + #[tokio::test] + async fn test_encode_single_message_multiple_in_schema() { + let _m = mock("GET", "/subjects/nl.openweb.data.Heartbeat/versions/latest") + .with_status(200) + .with_header("content-type", "application/vnd.schemaregistry.v1+json") + .with_body(&get_proto_body(get_proto_complex(), 7)) + .create(); + + let sr_settings = SrSettings::new(format!("http://{}", server_address())); + let mut encoder = ProtoRawEncoder::new(sr_settings); + let strategy = + SubjectNameStrategy::RecordNameStrategy(String::from("nl.openweb.data.Heartbeat")); + + assert_eq!( + encoder + .encode_single_message(get_proto_complex_only_data(), strategy,) + .await + .is_err(), + true + ) + } + #[tokio::test] async fn test_encode_cache() { let sr_settings = SrSettings::new(format!("http://{}", server_address())); @@ -329,7 +348,7 @@ mod tests { let encoded_data = encoder .encode( - get_proto_complex_proto_test_message_data_only(), + get_proto_complex_only_data(), "org.schema_registry_test_app.proto.ProtoTest", strategy, ) @@ -425,10 +444,7 @@ mod tests { .unwrap() .unwrap(); - assert_eq!( - raw_result.bytes, - get_proto_complex_proto_test_message_data_only() - ) + assert_eq!(raw_result.bytes, get_proto_complex_only_data()) } #[test] diff --git a/src/blocking/proto_raw.rs b/src/blocking/proto_raw.rs index 0deb0ff..92c2780 100644 --- a/src/blocking/proto_raw.rs +++ b/src/blocking/proto_raw.rs @@ -169,7 +169,7 @@ mod tests { }; use test_utils::{ get_proto_body, get_proto_body_with_reference, get_proto_complex, - get_proto_complex_proto_test_message, get_proto_complex_proto_test_message_data_only, + get_proto_complex_only_data, get_proto_complex_proto_test_message, get_proto_complex_references, get_proto_hb_101, get_proto_hb_101_only_data, get_proto_hb_schema, get_proto_result, }; @@ -212,15 +212,33 @@ mod tests { SubjectNameStrategy::RecordNameStrategy(String::from("nl.openweb.data.Heartbeat")); let encoded_data = encoder - .encode_single_message( - get_proto_hb_101_only_data(), - &strategy, - ) + .encode_single_message(get_proto_hb_101_only_data(), &strategy) .unwrap(); assert_eq!(encoded_data, get_proto_hb_101()) } + #[test] + fn test_encode_single_message_multiple_in_schema() { + let _m = mock("GET", "/subjects/nl.openweb.data.Heartbeat/versions/latest") + .with_status(200) + .with_header("content-type", "application/vnd.schemaregistry.v1+json") + .with_body(&get_proto_body(get_proto_complex(), 7)) + .create(); + + let sr_settings = SrSettings::new(format!("http://{}", server_address())); + let mut encoder = ProtoRawEncoder::new(sr_settings); + let strategy = + SubjectNameStrategy::RecordNameStrategy(String::from("nl.openweb.data.Heartbeat")); + + assert_eq!( + encoder + .encode_single_message(get_proto_complex_only_data(), &strategy,) + .is_err(), + true + ) + } + #[test] fn test_encode_cache() { let sr_settings = SrSettings::new(format!("http://{}", server_address())); @@ -302,7 +320,7 @@ mod tests { let encoded_data = encoder .encode( - get_proto_complex_proto_test_message_data_only(), + get_proto_complex_only_data(), "org.schema_registry_test_app.proto.ProtoTest", &strategy, ) @@ -396,10 +414,7 @@ mod tests { Err(e) => panic!("Error: {:?}, while none expected", e), Ok(v) => panic!("Other value: {:?} than expected Message", v), }; - assert_eq!( - raw_result.bytes, - get_proto_complex_proto_test_message_data_only() - ) + assert_eq!(raw_result.bytes, get_proto_complex_only_data()) } #[test] diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 26ee383..9733a8f 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -34,7 +34,7 @@ pub fn get_proto_hb_101() -> &'static [u8] { &[0, 0, 0, 0, 7, 0, 8, 101] } -pub fn get_proto_complex_proto_test_message_data_only() -> &'static [u8] { +pub fn get_proto_complex_only_data() -> &'static [u8] { &get_proto_complex_proto_test_message()[7..] }