Skip to content

Commit

Permalink
Merge pull request #1304 from YuliaProkopovych/unitore
Browse files Browse the repository at this point in the history
READY(unitore): Fix failing tests
  • Loading branch information
Wandalen authored Apr 25, 2024
2 parents b8be5b7 + 8d68ce6 commit 9bbdd13
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 39 deletions.
5 changes: 2 additions & 3 deletions module/move/unitore/src/action/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() );

Expand Down Expand Up @@ -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 = "";

Expand All @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion module/move/unitore/src/action/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions module/move/unitore/src/action/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -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()
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions module/move/unitore/src/action/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 )?;
Expand Down
6 changes: 3 additions & 3 deletions module/move/unitore/src/sled_adapter/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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? )
Expand All @@ -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 )
Expand All @@ -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 )
}
}
8 changes: 4 additions & 4 deletions module/move/unitore/src/sled_adapter/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
;

Expand Down Expand Up @@ -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" )?
;
Expand All @@ -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" )?
;
Expand Down Expand Up @@ -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" )?
;
Expand Down
6 changes: 3 additions & 3 deletions module/move/unitore/src/sled_adapter/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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" )?
;
Expand All @@ -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" )?
;
Expand Down
14 changes: 5 additions & 9 deletions module/move/unitore/src/sled_adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
}
}

Expand Down Expand Up @@ -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 ) ) ) )
}
}

Expand All @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions module/move/unitore/src/sled_adapter/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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?;

Expand Down
3 changes: 2 additions & 1 deletion module/move/unitore/tests/config_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
;

Expand Down
3 changes: 2 additions & 1 deletion module/move/unitore/tests/config_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
;

Expand Down
10 changes: 7 additions & 3 deletions module/move/unitore/tests/frames_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
;

Expand Down Expand Up @@ -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 )
;

Expand Down
6 changes: 4 additions & 2 deletions module/move/unitore/tests/table_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
4 changes: 3 additions & 1 deletion module/move/unitore/tests/tables_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
;

Expand Down

0 comments on commit 9bbdd13

Please sign in to comment.