From 4e1913dfe1fab6d6e711f8d9c4531867ad027e99 Mon Sep 17 00:00:00 2001 From: sfauvel Date: Thu, 20 Feb 2025 12:14:56 +0100 Subject: [PATCH] fix: add `check-all-features-set` in `mithril-client` and fix code under features --- mithril-client/Makefile | 17 +++++++ .../src/cardano_database_client/api.rs | 47 ++++++++++++++++--- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/mithril-client/Makefile b/mithril-client/Makefile index 5562910930e..5d44d63acf8 100644 --- a/mithril-client/Makefile +++ b/mithril-client/Makefile @@ -6,6 +6,7 @@ args = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}` CARGO = cargo +FEATURES := fs unstable all: test build @@ -25,3 +26,19 @@ clean: doc: ${CARGO} doc --no-deps --open --features full + +# Compute the powerset of all the given features and save it to a file +.feature-sets: + powerset() { [ $$# -eq 0 ] && echo || (shift; powerset "$$@") | while read r ; do echo "$$1 $$r"; echo "$$r"; done };\ + powerset $$(echo "$(FEATURES)") > .features-sets + +check-all-features-set: .feature-sets + # Read the file to run cargo clippy on all those features sets + cat .features-sets | while read features_set; do \ + echo "Clippy client with feature '$$features_set''"; \ + ${CARGO} clippy -p mithril-client --features "$$features_set"; \ + done + echo "Clippy client without features"; \ + ${CARGO} clippy -p mithril-client + + rm .features-sets diff --git a/mithril-client/src/cardano_database_client/api.rs b/mithril-client/src/cardano_database_client/api.rs index 9dcef1bb9ab..11673885b34 100644 --- a/mithril-client/src/cardano_database_client/api.rs +++ b/mithril-client/src/cardano_database_client/api.rs @@ -115,17 +115,18 @@ impl CardanoDatabaseClient { pub(crate) mod test_dependency_injector { use super::*; - use crate::{ - aggregator_client::MockAggregatorClient, - feedback::FeedbackReceiver, - file_downloader::{FileDownloader, MockFileDownloaderBuilder}, - test_utils, - }; + use crate::aggregator_client::MockAggregatorClient; + #[cfg(feature = "fs")] + use crate::file_downloader::{FileDownloader, MockFileDownloaderBuilder}; + #[cfg(feature = "fs")] + use crate::{feedback::FeedbackReceiver, test_utils}; /// Dependency injector for `CardanoDatabaseClient` for testing purposes. pub(crate) struct CardanoDatabaseClientDependencyInjector { aggregator_client: MockAggregatorClient, + #[cfg(feature = "fs")] http_file_downloader: Arc, + #[cfg(feature = "fs")] feedback_receivers: Vec>, } @@ -133,6 +134,7 @@ pub(crate) mod test_dependency_injector { pub(crate) fn new() -> Self { Self { aggregator_client: MockAggregatorClient::new(), + #[cfg(feature = "fs")] http_file_downloader: Arc::new( MockFileDownloaderBuilder::default() .with_compression(None) @@ -140,6 +142,7 @@ pub(crate) mod test_dependency_injector { .with_times(0) .build(), ), + #[cfg(feature = "fs")] feedback_receivers: vec![], } } @@ -153,6 +156,7 @@ pub(crate) mod test_dependency_injector { self } + #[cfg(feature = "fs")] pub(crate) fn with_http_file_downloader( self, http_file_downloader: Arc, @@ -163,6 +167,7 @@ pub(crate) mod test_dependency_injector { } } + #[cfg(feature = "fs")] pub(crate) fn with_feedback_receivers( self, feedback_receivers: &[Arc], @@ -173,6 +178,7 @@ pub(crate) mod test_dependency_injector { } } + #[cfg(feature = "fs")] pub(crate) fn build_cardano_database_client(self) -> CardanoDatabaseClient { CardanoDatabaseClient::new( Arc::new(self.aggregator_client), @@ -181,15 +187,23 @@ pub(crate) mod test_dependency_injector { test_utils::test_logger(), ) } + + #[cfg(not(feature = "fs"))] + pub(crate) fn build_cardano_database_client(self) -> CardanoDatabaseClient { + CardanoDatabaseClient::new(Arc::new(self.aggregator_client)) + } } mod tests { use mockall::predicate; - use crate::{aggregator_client::AggregatorRequest, feedback::StackFeedbackReceiver}; + use crate::aggregator_client::AggregatorRequest; + #[cfg(feature = "fs")] + use crate::feedback::StackFeedbackReceiver; use super::*; + #[cfg(feature = "fs")] #[test] fn test_cardano_database_client_dependency_injector_builds() { let _ = CardanoDatabaseClientDependencyInjector::new() @@ -214,5 +228,24 @@ pub(crate) mod test_dependency_injector { .with_feedback_receivers(&[Arc::new(StackFeedbackReceiver::new())]) .build_cardano_database_client(); } + + #[cfg(not(feature = "fs"))] + #[test] + fn test_cardano_database_client_dependency_injector_builds() { + let _ = CardanoDatabaseClientDependencyInjector::new() + .with_aggregator_client_mock_config(|http_client| { + let message = vec![CardanoDatabaseSnapshotListItem { + hash: "hash-123".to_string(), + ..CardanoDatabaseSnapshotListItem::dummy() + }]; + http_client + .expect_get_content() + .with(predicate::eq( + AggregatorRequest::ListCardanoDatabaseSnapshots, + )) + .return_once(move |_| Ok(serde_json::to_string(&message).unwrap())); + }) + .build_cardano_database_client(); + } } }