Skip to content

Commit

Permalink
Add test to encode single message when there are multiple messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
gklijs committed Jul 5, 2021
1 parent ef3caa6 commit 5b93b80
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
36 changes: 26 additions & 10 deletions src/async_impl/proto_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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]
Expand Down
35 changes: 25 additions & 10 deletions src/blocking/proto_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..]
}

Expand Down

0 comments on commit 5b93b80

Please sign in to comment.