Skip to content

Commit

Permalink
Ran a cargo format.
Browse files Browse the repository at this point in the history
  • Loading branch information
gklijs committed Oct 13, 2024
1 parent e132df6 commit f9ecaec
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/async_impl/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use crate::async_impl::schema_registry::{
get_referenced_schema, get_schema_by_id_and_type, get_schema_by_subject, SrSettings,
};
use crate::avro_common::{
get_name, item_to_bytes, replace_reference, values_to_bytes, AvroSchema, DecodeResult, record_to_bytes,
DecodeResultWithSchema,
get_name, item_to_bytes, record_to_bytes, replace_reference, values_to_bytes, AvroSchema,
DecodeResult, DecodeResultWithSchema,
};
use crate::error::SRCError;
use crate::schema_registry_common::{
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/easy_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ mod tests {
use crate::async_impl::schema_registry::SrSettings;
use crate::schema_registry_common::{get_payload, SubjectNameStrategy};

use mockito::Server;
use serde_json::Value;
use std::fs::{read_to_string, File};
use mockito::Server;
use test_utils::{get_json_body, json_result_java_bytes, json_result_schema};

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/easy_proto_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ impl EasyProtoDecoder {

#[cfg(test)]
mod tests {
use mockito::Server;
use crate::async_impl::easy_proto_decoder::EasyProtoDecoder;
use crate::async_impl::schema_registry::SrSettings;
use mockito::Server;

use protofish::decode::Value;
use test_utils::{get_proto_body, get_proto_hb_101, get_proto_hb_schema};
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/easy_proto_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ impl EasyProtoRawEncoder {

#[cfg(test)]
mod tests {
use mockito::Server;
use crate::async_impl::easy_proto_raw::{EasyProtoRawDecoder, EasyProtoRawEncoder};
use crate::async_impl::schema_registry::SrSettings;
use crate::schema_registry_common::SubjectNameStrategy;
use mockito::Server;

use test_utils::{
get_proto_body, get_proto_hb_101, get_proto_hb_101_only_data, get_proto_hb_schema,
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ pub struct DecodeResult {

#[cfg(test)]
mod tests {
use std::fs::{read_to_string, File};
use mockito::Server;
use std::fs::{read_to_string, File};

use serde_json::Value;

Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/proto_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ async fn to_vec_of_schemas(

#[cfg(test)]
mod tests {
use mockito::Server;
use crate::async_impl::proto_decoder::ProtoDecoder;
use crate::async_impl::schema_registry::SrSettings;
use mockito::Server;
use protofish::prelude::Value;
use test_utils::{
get_proto_complex, get_proto_complex_proto_test_message, get_proto_complex_references,
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/proto_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ pub struct RawDecodeResult {

#[cfg(test)]
mod tests {
use mockito::Server;
use crate::async_impl::proto_raw::{ProtoRawDecoder, ProtoRawEncoder};
use crate::async_impl::schema_registry::SrSettings;
use crate::schema_registry_common::{
SchemaType, SubjectNameStrategy, SuppliedReference, SuppliedSchema,
};
use mockito::Server;
use test_utils::{
get_proto_body, get_proto_body_with_reference, get_proto_complex,
get_proto_complex_only_data, get_proto_complex_proto_test_message,
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/schema_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ async fn perform_single_versions_call(

#[cfg(test)]
mod tests {
use std::time::Duration;
use mockito::Server;
use std::time::Duration;

use crate::async_impl::schema_registry::{
get_schema_by_id, get_schema_by_id_and_type, SrSettings,
Expand Down
7 changes: 1 addition & 6 deletions src/avro_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ pub(crate) fn values_to_bytes(
avro_schema: &AvroSchema,
values: Vec<(&str, Value)>,
) -> Result<Vec<u8>, SRCError> {

let mut record = match Record::new(&avro_schema.parsed) {
Some(v) => v,
None => {
Expand All @@ -136,7 +135,6 @@ pub(crate) fn values_to_bytes(
to_bytes(avro_schema, Value::from(record))
}


/// Using the schema with an item implementing serialize the item will be correctly deserialized
/// according to the avro specification.
pub(crate) fn item_to_bytes(
Expand All @@ -155,10 +153,7 @@ pub(crate) fn item_to_bytes(
}
}

pub(crate) fn record_to_bytes(
avro_schema: &AvroSchema,
item: Value,
) -> Result<Vec<u8>, SRCError> {
pub(crate) fn record_to_bytes(avro_schema: &AvroSchema, item: Value) -> Result<Vec<u8>, SRCError> {
to_bytes(avro_schema, item)
}

Expand Down
26 changes: 21 additions & 5 deletions src/schema_registry_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,40 @@ pub(crate) fn url_for_call(call: &SrCall, base_url: &str) -> String {
SrCall::GetById(id) => format!("{}/schemas/ids/{}?deleted=true", base_url, id),
SrCall::GetLatest(subject) => {
// Use escape sequences instead of slashes in the subject
format!("{}/subjects/{}/versions/latest", base_url, subject.replace("/", "%2F"))
format!(
"{}/subjects/{}/versions/latest",
base_url,
subject.replace("/", "%2F")
)
}
SrCall::GetBySubjectAndVersion(subject, version) => {
// Use escape sequences instead of slashes in the subject
format!("{}/subjects/{}/versions/{}", base_url, subject.replace("/", "%2F"), version)
format!(
"{}/subjects/{}/versions/{}",
base_url,
subject.replace("/", "%2F"),
version
)
}
SrCall::PostNew(subject, _) => {
// Use escape sequences instead of slashes in the subject
format!("{}/subjects/{}/versions", base_url, subject.replace("/", "%2F"))
format!(
"{}/subjects/{}/versions",
base_url,
subject.replace("/", "%2F")
)
}
SrCall::PostForVersion(subject, _) => {
// Use escape sequences instead of slashes in the subject
format!("{}/subjects/{}?deleted=false", base_url, subject.replace("/", "%2F"))
format!(
"{}/subjects/{}?deleted=false",
base_url,
subject.replace("/", "%2F")
)
}
}
}


/// Creates payload that can be included as a key or value on a kafka record
pub fn get_payload(id: u32, encoded_bytes: Vec<u8>) -> Vec<u8> {
let mut payload = vec![0u8];
Expand Down
2 changes: 1 addition & 1 deletion tests/blocking/kafka_consumer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rdkafka::config::{ClientConfig, RDKafkaLogLevel};
use rdkafka::consumer::{Consumer, DefaultConsumerContext};
use rdkafka::consumer::base_consumer::BaseConsumer;
use rdkafka::consumer::{Consumer, DefaultConsumerContext};

type TestConsumer = BaseConsumer<DefaultConsumerContext>;

Expand Down

0 comments on commit f9ecaec

Please sign in to comment.