From 8d68ce672fca6abd41a85f9029d150522b108091 Mon Sep 17 00:00:00 2001 From: YuliaProkopovych Date: Thu, 25 Apr 2024 16:52:16 +0300 Subject: [PATCH] fix tests path --- module/move/unitore/src/action/config.rs | 5 ++--- module/move/unitore/src/action/feed.rs | 2 +- module/move/unitore/src/action/frame.rs | 8 ++++---- module/move/unitore/src/action/table.rs | 4 ++-- module/move/unitore/src/sled_adapter/config.rs | 6 +++--- module/move/unitore/src/sled_adapter/feed.rs | 8 ++++---- module/move/unitore/src/sled_adapter/frame.rs | 6 +++--- module/move/unitore/src/sled_adapter/mod.rs | 14 +++++--------- module/move/unitore/src/sled_adapter/table.rs | 4 ++-- module/move/unitore/tests/config_add.rs | 3 ++- module/move/unitore/tests/config_delete.rs | 3 ++- module/move/unitore/tests/frames_download.rs | 10 +++++++--- module/move/unitore/tests/table_list.rs | 6 ++++-- module/move/unitore/tests/tables_list.rs | 4 +++- 14 files changed, 44 insertions(+), 39 deletions(-) diff --git a/module/move/unitore/src/action/config.rs b/module/move/unitore/src/action/config.rs index 49b63a4773..fae3bcf67d 100644 --- a/module/move/unitore/src/action/config.rs +++ b/module/move/unitore/src/action/config.rs @@ -40,7 +40,6 @@ pub async fn config_add( mut storage : FeedStorage< SledStorage >, path : &PathB return Err( error_tools::for_app::Error::msg( err_str ) ); } - //let abs_path = proper_path_tools::path::canonicalize( path )?; let abs_path = path.canonicalize()?; let config = Config::new( abs_path.to_string_lossy().to_string() ); @@ -101,7 +100,7 @@ impl ConfigReport impl std::fmt::Display for ConfigReport { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { const EMPTY_CELL : &'static str = ""; @@ -112,7 +111,7 @@ impl std::fmt::Display for ConfigReport writeln!( f, "Added {} config file(s)", number )?; writeln!( f, - "Added {} feeds", + "Added {} feed(s)", self.new_feeds .as_ref() .and_then( | payload | diff --git a/module/move/unitore/src/action/feed.rs b/module/move/unitore/src/action/feed.rs index f7840a5f55..70063de854 100644 --- a/module/move/unitore/src/action/feed.rs +++ b/module/move/unitore/src/action/feed.rs @@ -29,7 +29,7 @@ impl FeedsReport impl std::fmt::Display for FeedsReport { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { writeln!( f, "Selected feeds:" )?; if !self.0.selected_rows.is_empty() diff --git a/module/move/unitore/src/action/frame.rs b/module/move/unitore/src/action/frame.rs index f26d538e20..2acb4cd168 100644 --- a/module/move/unitore/src/action/frame.rs +++ b/module/move/unitore/src/action/frame.rs @@ -111,7 +111,7 @@ impl FramesReport impl std::fmt::Display for FramesReport { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { let initial = vec![ vec![ format!( "Feed title: {}", self.feed_link ) ] ]; let table = tool::table_display::table_with_headers( initial[ 0 ].clone(), Vec::new() ); @@ -192,7 +192,7 @@ impl SelectedEntries impl std::fmt::Display for SelectedEntries { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { if !self.selected_columns.is_empty() { @@ -216,7 +216,7 @@ pub struct UpdateReport( pub Vec< FramesReport > ); impl std::fmt::Display for UpdateReport { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { for report in &self.0 { @@ -244,7 +244,7 @@ pub struct ListReport( pub Vec< FramesReport > ); impl std::fmt::Display for ListReport { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { for report in &self.0 { diff --git a/module/move/unitore/src/action/table.rs b/module/move/unitore/src/action/table.rs index 5e0c92663b..ce9a4e756f 100644 --- a/module/move/unitore/src/action/table.rs +++ b/module/move/unitore/src/action/table.rs @@ -245,7 +245,7 @@ pub struct TablesColumnsReport( pub Vec< ColumnsReport > ); impl std::fmt::Display for TablesColumnsReport { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { for report in &self.0 { @@ -283,7 +283,7 @@ impl ColumnsReport impl std::fmt::Display for ColumnsReport { - fn fmt( &self, f : &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { writeln!( f, "Table name: {}", self.table_name )?; writeln!( f, "Description: {}", self.table_description )?; diff --git a/module/move/unitore/src/sled_adapter/config.rs b/module/move/unitore/src/sled_adapter/config.rs index 35ad1ae3cd..a3b0cc73d8 100644 --- a/module/move/unitore/src/sled_adapter/config.rs +++ b/module/move/unitore/src/sled_adapter/config.rs @@ -26,7 +26,7 @@ impl ConfigStore for FeedStorage< SledStorage > "path", ) .values( vec![ vec![ text( config.path() ) ] ] ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await; Ok( res? ) @@ -37,7 +37,7 @@ impl ConfigStore for FeedStorage< SledStorage > let res = table( "config" ) .delete() .filter( col( "path" ).eq( format!( "'{}'", config.path() ) ) ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await?; if res == Payload::Delete( 0 ) @@ -50,7 +50,7 @@ impl ConfigStore for FeedStorage< SledStorage > async fn config_list( &mut self ) -> Result< Payload > { - let res = table( "config" ).select().execute( &mut *self.storage.lock().await ).await?; + let res = table( "config" ).select().execute( &mut *self.0.lock().await ).await?; Ok( res ) } } diff --git a/module/move/unitore/src/sled_adapter/feed.rs b/module/move/unitore/src/sled_adapter/feed.rs index 2659657103..fb38e02075 100644 --- a/module/move/unitore/src/sled_adapter/feed.rs +++ b/module/move/unitore/src/sled_adapter/feed.rs @@ -35,7 +35,7 @@ impl FeedStore for FeedStorage< SledStorage > let res = table( "feed" ) .select() .project( "title, link, update_period, config_file" ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await? ; @@ -74,7 +74,7 @@ impl FeedStore for FeedStorage< SledStorage > feed.published.map( | d | timestamp( d.to_rfc3339_opts( SecondsFormat::Millis, true ) ) ).unwrap_or( null() ), ) .filter( col( "link" ).eq( feed.link.to_string() ) ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await .context( "Failed to insert feed" )? ; @@ -101,7 +101,7 @@ impl FeedStore for FeedStorage< SledStorage > .select() .filter( col( "feed_link" ).eq( text( feed.2.to_string() ) ) ) .project( "id, published" ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await .context( "Failed to get existing frames while saving new frames" )? ; @@ -187,7 +187,7 @@ impl FeedStore for FeedStorage< SledStorage > config_file", ) .values( feeds_rows ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await .context( "Failed to insert feeds" )? ; diff --git a/module/move/unitore/src/sled_adapter/frame.rs b/module/move/unitore/src/sled_adapter/frame.rs index e2224f4958..84d4687bf4 100644 --- a/module/move/unitore/src/sled_adapter/frame.rs +++ b/module/move/unitore/src/sled_adapter/frame.rs @@ -23,7 +23,7 @@ impl FrameStore for FeedStorage< SledStorage > { async fn frames_list( &mut self ) -> Result< ListReport > { - let res = table( "frame" ).select().execute( &mut *self.storage.lock().await ).await?; + let res = table( "frame" ).select().execute( &mut *self.0.lock().await ).await?; let mut reports = Vec::new(); let all_frames = @@ -91,7 +91,7 @@ impl FrameStore for FeedStorage< SledStorage > feed_link" ) .values( entries_rows ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await .context( "Failed to insert frames" )? ; @@ -114,7 +114,7 @@ impl FrameStore for FeedStorage< SledStorage > .set( "published", entry[ 8 ].to_owned() ) .set( "media", entry[ 9 ].to_owned() ) .filter( col( "id" ).eq( entry[ 0 ].to_owned() ) ) - .execute( &mut *self.storage.lock().await ) + .execute( &mut *self.0.lock().await ) .await .context( "Failed to update frames" )? ; diff --git a/module/move/unitore/src/sled_adapter/mod.rs b/module/move/unitore/src/sled_adapter/mod.rs index 511d866e8e..885d5b9889 100644 --- a/module/move/unitore/src/sled_adapter/mod.rs +++ b/module/move/unitore/src/sled_adapter/mod.rs @@ -23,17 +23,13 @@ mod config; /// Storage for feed frames. #[ derive( Clone ) ] -pub struct FeedStorage< S : GStore + GStoreMut + Send > -{ - /// GlueSQL storage. - pub storage : Arc< Mutex< Glue< S > > >, -} +pub struct FeedStorage< S : GStore + GStoreMut + Send >( Arc< Mutex< Glue< S > > > ); impl< S : GStore + GStoreMut + Send > std::fmt::Debug for FeedStorage< S > { - fn fmt( &self, f: &mut std::fmt::Formatter<'_> ) -> std::fmt::Result + fn fmt( &self, f : &mut std::fmt::Formatter< '_ > ) -> std::fmt::Result { - writeln!(f, "GlueSQL storage" ) + writeln!( f, "GlueSQL storage" ) } } @@ -93,7 +89,7 @@ impl FeedStorage< SledStorage > frame_table.execute( &mut glue ).await?; - Ok( Self{ storage : Arc::new( Mutex::new( glue ) ) } ) + Ok( Self( Arc::new( Mutex::new( glue ) ) ) ) } } @@ -111,7 +107,7 @@ impl< S : GStore + GStoreMut + Send > Store for FeedStorage< S > { async fn execute_query( &mut self, query : String ) -> Result< QueryReport > { - let glue = &mut *self.storage.lock().await; + let glue = &mut *self.0.lock().await; let payloads = glue.execute( &query ).await.context( "Failed to execute query" )?; let report = QueryReport ( payloads ); diff --git a/module/move/unitore/src/sled_adapter/table.rs b/module/move/unitore/src/sled_adapter/table.rs index ddf0664bfc..71763918ee 100644 --- a/module/move/unitore/src/sled_adapter/table.rs +++ b/module/move/unitore/src/sled_adapter/table.rs @@ -16,7 +16,7 @@ impl TableStore for FeedStorage< SledStorage > { async fn tables_list( &mut self ) -> Result< TablesReport > { - let glue = &mut *self.storage.lock().await; + let glue = &mut *self.0.lock().await; let payloads = glue.execute( "SELECT * FROM GLUE_TABLE_COLUMNS" ).await?; let report = TablesReport::new( payloads ); @@ -26,7 +26,7 @@ impl TableStore for FeedStorage< SledStorage > async fn table_list( &mut self, table_name : String ) -> Result< Vec< Payload > > { - let glue = &mut *self.storage.lock().await; + let glue = &mut *self.0.lock().await; let query_str = format!( "SELECT * FROM GLUE_TABLE_COLUMNS WHERE TABLE_NAME='{}'", table_name ); let payloads = glue.execute( &query_str ).await?; diff --git a/module/move/unitore/tests/config_add.rs b/module/move/unitore/tests/config_add.rs index a3de7479b7..d1a2dca5da 100644 --- a/module/move/unitore/tests/config_add.rs +++ b/module/move/unitore/tests/config_add.rs @@ -12,9 +12,10 @@ use error_tools::Result; async fn config_add() -> Result< () > { let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); + let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); let config = Config::default() - .path( "./test_add".to_owned() ) + .path( format!( "./{}", temp_path ) ) .temporary( true ) ; diff --git a/module/move/unitore/tests/config_delete.rs b/module/move/unitore/tests/config_delete.rs index 95870d4700..d35c5bab7c 100644 --- a/module/move/unitore/tests/config_delete.rs +++ b/module/move/unitore/tests/config_delete.rs @@ -16,9 +16,10 @@ use error_tools::Result; async fn config_delete() -> Result< () > { let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); + let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); let config = Config::default() - .path( "./test_del".to_owned() ) + .path( format!( "./{}", temp_path ) ) .temporary( true ) ; diff --git a/module/move/unitore/tests/frames_download.rs b/module/move/unitore/tests/frames_download.rs index ad5c3c2ff6..ae8119a71d 100644 --- a/module/move/unitore/tests/frames_download.rs +++ b/module/move/unitore/tests/frames_download.rs @@ -20,8 +20,10 @@ use error_tools::Result; #[ tokio::test ] async fn test_save() -> Result< () > { - let config = gluesql::sled_storage::sled::Config::default() - .path( "./test_save".to_owned() ) + let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + + let config = Config::default() + .path( format!( "./{}", temp_path ) ) .temporary( true ) ; @@ -50,8 +52,10 @@ async fn test_save() -> Result< () > #[ tokio::test ] async fn test_update() -> Result< () > { + let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let config = Config::default() - .path( "./test_update".to_owned() ) + .path( format!( "./{}", temp_path ) ) .temporary( true ) ; diff --git a/module/move/unitore/tests/table_list.rs b/module/move/unitore/tests/table_list.rs index dc840b3633..188d1a3131 100644 --- a/module/move/unitore/tests/table_list.rs +++ b/module/move/unitore/tests/table_list.rs @@ -13,12 +13,14 @@ use error_tools::Result; #[ tokio::test ] async fn table_list() -> Result< () > { + let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let config = Config::default() - .path( "./test_list".to_owned() ) + .path( format!( "./{}", temp_path ) ) .temporary( true ) ; - let mut feed_storage = FeedStorage::init_storage( &config ).await?; + let mut feed_storage = FeedStorage::init_storage( &config ).await?; let res = feed_storage.table_list( String::from( "feed" ) ).await?; if let Payload::Select { labels: _, rows } = &res[ 0 ] diff --git a/module/move/unitore/tests/tables_list.rs b/module/move/unitore/tests/tables_list.rs index 6b306b1c19..0972041704 100644 --- a/module/move/unitore/tests/tables_list.rs +++ b/module/move/unitore/tests/tables_list.rs @@ -9,8 +9,10 @@ use error_tools::Result; #[ tokio::test ] async fn tables_list() -> Result< () > { + let temp_path = proper_path_tools::path::unique_folder_name().unwrap(); + let config = Config::default() - .path( "./test_list".to_owned() ) + .path( format!( "./{}", temp_path ) ) .temporary( true ) ;