Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkarthik committed Feb 10, 2025
1 parent 2157b43 commit ec90d44
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
12 changes: 7 additions & 5 deletions ndc-test/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ impl fmt::Display for Error {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Error::Serde(e) => ("serde", e.to_string()),
Error::SerdeWithMessage(e, message) => ("serde", format!("{}: {}", message, e)),
Error::SerdeWithMessage(e, message) => ("serde", format!("{message}: {e}")),
Error::Io(e) => ("IO", e.to_string()),
Error::ConnectorError(e) => ("response", format!("status code {} error {}", e.status, e.raw_response.to_string())),
Error::ConnectorError(e) => (
"response",
format!("status code {} error {}", e.status, e.raw_response),
),
Error::InvalidConnectorError(e) => ("response", format!("status code {}", e.status)),
Error::InvalidBaseURL => ("url", "invalid base URL".into()),
};
Expand All @@ -66,8 +69,7 @@ impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Error::Reqwest(e) => Some(e),
Error::Serde(e) => Some(e),
Error::SerdeWithMessage(e, _) => Some(e),
Error::Serde(e) | Error::SerdeWithMessage(e, _) => Some(e),
Error::Io(e) => Some(e),
Error::ConnectorError(_) | Error::InvalidConnectorError(_) | Error::InvalidBaseURL => {
None
Expand Down Expand Up @@ -220,7 +222,7 @@ fn construct_error(
Error::ConnectorError(connector_error)
}
Err(e) => {
let message = format!("failed to deserialize error response: {}", e);
let message = format!("failed to deserialize error response: {e}");
Error::SerdeWithMessage(e, message)
}
}
Expand Down
4 changes: 2 additions & 2 deletions ndc-test/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ pub type OtherError = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("error communicating with the connector: {0}")]
CommunicationError(#[from] super::client::Error),
CommunicationError(#[from] Box<super::client::Error>),
#[error("error communicating with the connector: {0} ")]
CommunicationErrorWithContent(super::client::Error),
CommunicationErrorWithContent(Box<super::client::Error>),
#[error("error generating test data: {0}")]
StrategyError(#[from] rand::Error),
#[error("error parsing semver range: {0}")]
Expand Down
18 changes: 9 additions & 9 deletions ndc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ use crate::test_cases::query::validate::ValidatingConnector;
#[async_trait(?Send)]
impl Connector for client::Configuration {
async fn get_capabilities(&self) -> Result<models::CapabilitiesResponse> {
Ok(client::capabilities_get(self).await?)
Ok(client::capabilities_get(self).await.map_err(Box::new)?)
}

async fn get_schema(&self) -> Result<models::SchemaResponse> {
Ok(client::schema_get(self).await?)
Ok(client::schema_get(self).await.map_err(Box::new)?)
}

async fn query(&self, request: models::QueryRequest) -> Result<models::QueryResponse> {
Ok(client::query_post(self, request).await.map_err(Error::CommunicationErrorWithContent)?)
Ok(client::query_post(self, request)
.await
.map_err(|e| Error::CommunicationErrorWithContent(Box::new(e)))?)
}

async fn mutation(&self, request: models::MutationRequest) -> Result<models::MutationResponse> {
Ok(client::mutation_post(self, request).await?)
Ok(client::mutation_post(self, request)
.await
.map_err(Box::new)?)
}
}

Expand Down Expand Up @@ -164,13 +168,9 @@ pub async fn test_snapshots_in_directory_with<

match response {
Ok(response) => snapshot_test(snapshot_path, &response),
Err(e) => {
Err(e)
}
Err(e) => Err(e),
}



// snapshot_test(snapshot_path, &response)
}
}
Expand Down
9 changes: 3 additions & 6 deletions ndc-test/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,16 @@ where
if snapshot_path.exists() {
let snapshot_file = File::open(snapshot_path).map_err(Error::CannotOpenSnapshotFile)?;
let snapshot: R = serde_json::from_reader(snapshot_file)?;
let compare: pretty_assertions::Comparison<R, R> = pretty_assertions::Comparison::new(&snapshot, expected);



let compare: pretty_assertions::Comparison<R, R> =
pretty_assertions::Comparison::new(&snapshot, expected);

if snapshot != *expected {
println!("Expected: {:?}", expected);
let actual = serde_json::to_string_pretty(&expected)?;

return Err(Error::ResponseDidNotMatchSnapshot(
snapshot_path.to_path_buf(),
actual,
format!("{}", compare),
format!("{compare}"),
));
}
} else {
Expand Down

0 comments on commit ec90d44

Please sign in to comment.