From 530d27f98cfadf081366220caf48eebef573fbd9 Mon Sep 17 00:00:00 2001 From: YuliaProkopovych Date: Tue, 9 Apr 2024 16:53:03 +0300 Subject: [PATCH] fix commands --- module/move/unitore/Readme.md | 2 +- module/move/unitore/src/action/config.rs | 23 ++--- module/move/unitore/src/action/feed.rs | 8 +- module/move/unitore/src/action/frame.rs | 11 +-- module/move/unitore/src/action/query.rs | 14 +-- module/move/unitore/src/action/table.rs | 46 ++++------ module/move/unitore/src/command/config.rs | 86 ++++++++++++------- module/move/unitore/src/command/feed.rs | 5 +- module/move/unitore/src/command/frame.rs | 8 +- module/move/unitore/src/command/query.rs | 41 +++++---- module/move/unitore/src/command/table.rs | 8 +- module/move/unitore/src/sled_adapter/frame.rs | 15 +++- module/move/unitore/src/sled_adapter/mod.rs | 51 +++++------ module/move/unitore/tests/config.rs | 70 --------------- module/move/unitore/tests/config_add.rs | 37 ++++++++ module/move/unitore/tests/config_delete.rs | 42 +++++++++ module/move/unitore/tests/table_list.rs | 45 ++++++++++ module/move/unitore/tests/tables_list.rs | 32 +++++++ 18 files changed, 316 insertions(+), 228 deletions(-) delete mode 100644 module/move/unitore/tests/config.rs create mode 100644 module/move/unitore/tests/config_add.rs create mode 100644 module/move/unitore/tests/config_delete.rs create mode 100644 module/move/unitore/tests/table_list.rs create mode 100644 module/move/unitore/tests/tables_list.rs diff --git a/module/move/unitore/Readme.md b/module/move/unitore/Readme.md index 3513ec3729..e631beb82b 100644 --- a/module/move/unitore/Readme.md +++ b/module/move/unitore/Readme.md @@ -47,7 +47,7 @@ cargo run .feeds.list ``` To get custom information about feeds or frames run SQL query to storage database using command `.query.execute` with query string: ```bash -cargo run .query.execute \'SELECT title, links, MIN\(published\) FROM frame\' +cargo run .query.execute 'SELECT title, links, MIN(published) FROM frame' ``` To remove config file from storage use command `.config.delete` with path to config file: ```bash diff --git a/module/move/unitore/src/action/config.rs b/module/move/unitore/src/action/config.rs index 5fd8dd84a9..49b63a4773 100644 --- a/module/move/unitore/src/action/config.rs +++ b/module/move/unitore/src/action/config.rs @@ -1,7 +1,9 @@ -//! Actions and report for commands for config files. +//! Actions and report for config files. + +use std::path::PathBuf; use crate::*; -use error_tools::{ err, for_app::Context, BasicError, Result }; +use error_tools::{ for_app::Context, Result }; use sled_adapter::FeedStorage; use entity:: { @@ -12,14 +14,8 @@ use action::Report; use gluesql::{ prelude::Payload, sled_storage::SledStorage }; /// Add configuration file with subscriptions to storage. -pub async fn config_add( mut storage : FeedStorage< SledStorage >, args : &wca::Args ) -> Result< impl Report > +pub async fn config_add( mut storage : FeedStorage< SledStorage >, path : &PathBuf ) -> Result< impl Report > { - let path : std::path::PathBuf = args - .get_owned::< wca::Value >( 0 ) - .ok_or_else::< BasicError, _ >( || err!( "Cannot get path argument for command .config.add" ) )? - .into() - ; - let path = proper_path_tools::path::normalize( path ); let mut err_str = format!( "Invalid path for config file {:?}", path ); @@ -66,14 +62,9 @@ pub async fn config_add( mut storage : FeedStorage< SledStorage >, args : &wca:: } /// Remove configuration file from storage. -pub async fn config_delete( mut storage : FeedStorage< SledStorage >, args : &wca::Args ) -> Result< impl Report > +pub async fn config_delete( mut storage : FeedStorage< SledStorage >, path : &PathBuf ) -> Result< impl Report > { - let path : std::path::PathBuf = args - .get_owned::< wca::Value >( 0 ) - .ok_or_else::< BasicError, _ >( || err!( "Cannot get path argument for command .config.delete" ) )? - .into() - ; - + let path = proper_path_tools::path::normalize( path ); let path = path.canonicalize().context( format!( "Invalid path for config file {:?}", path ) )?; let config = Config::new( path.to_string_lossy().to_string() ); diff --git a/module/move/unitore/src/action/feed.rs b/module/move/unitore/src/action/feed.rs index a2eed760e9..f7840a5f55 100644 --- a/module/move/unitore/src/action/feed.rs +++ b/module/move/unitore/src/action/feed.rs @@ -1,4 +1,4 @@ -//! Endpoints and report for feed commands. +//! Feed actions and reports. use crate::*; use action::{ Report, frame::SelectedEntries }; @@ -7,11 +7,7 @@ use entity::feed::FeedStore; use error_tools::Result; /// List all feeds from storage. -pub async fn feeds_list -( - mut storage : FeedStorage< gluesql::sled_storage::SledStorage >, - _args : &wca::Args, -) -> Result< impl Report > +pub async fn feeds_list( mut storage : FeedStorage< gluesql::sled_storage::SledStorage > ) -> Result< impl Report > { storage.feeds_list().await } diff --git a/module/move/unitore/src/action/frame.rs b/module/move/unitore/src/action/frame.rs index 1374988347..f26d538e20 100644 --- a/module/move/unitore/src/action/frame.rs +++ b/module/move/unitore/src/action/frame.rs @@ -1,4 +1,4 @@ -//! Frames commands actions. +//! Frames actions and reports. use crate::*; use sled_adapter::FeedStorage; @@ -16,11 +16,7 @@ use action::Report; // qqq : review the whole project and make sure all names are consitant: actions, commands, its tests /// List all frames. -pub async fn frames_list -( - mut storage : FeedStorage< SledStorage >, - _args : &wca::Args, -) -> Result< impl Report > +pub async fn frames_list( mut storage : FeedStorage< SledStorage > ) -> Result< impl Report > { storage.frames_list().await } @@ -28,8 +24,7 @@ pub async fn frames_list /// Update all frames from config files saved in storage. pub async fn frames_download ( - mut storage : FeedStorage< SledStorage >, - _args : &wca::Args, + mut storage : FeedStorage< SledStorage > ) -> Result< impl Report > { let payload = storage.config_list().await?; diff --git a/module/move/unitore/src/action/query.rs b/module/move/unitore/src/action/query.rs index c0ae448e0b..0f5edd06a7 100644 --- a/module/move/unitore/src/action/query.rs +++ b/module/move/unitore/src/action/query.rs @@ -1,4 +1,4 @@ -//! Query command endpoint and report. +//! Query actions and report. // qqq : don't use both // aaa : fixed @@ -6,22 +6,16 @@ use crate::*; use gluesql::core::executor::Payload; use sled_adapter::{ FeedStorage, Store }; use action::Report; -use error_tools::{ err, BasicError, Result }; +use error_tools::Result; /// Execute query specified in query string. pub async fn query_execute ( mut storage : FeedStorage< gluesql::sled_storage::SledStorage >, - args : &wca::Args, + query_str : String, ) -> Result< impl Report > { - let query = args - .get_owned::< Vec::< String > >( 0 ) - .ok_or_else::< BasicError, _ >( || err!( "Cannot get Query argument for command .query.execute" ) )? - .join( " " ) - ; - - storage.execute_query( query ).await + storage.execute_query( query_str ).await } const EMPTY_CELL : &'static str = ""; diff --git a/module/move/unitore/src/action/table.rs b/module/move/unitore/src/action/table.rs index 7fecad6115..5e0c92663b 100644 --- a/module/move/unitore/src/action/table.rs +++ b/module/move/unitore/src/action/table.rs @@ -1,4 +1,4 @@ -//! Tables metadata commands actions and reports. +//! Tables metadata actions and reports. use crate::*; use gluesql::prelude::Payload; @@ -12,12 +12,9 @@ use error_tools::Result; pub async fn table_list ( mut storage : FeedStorage< gluesql::sled_storage::SledStorage >, - args : &wca::Args, + table_name : Option< String >, ) -> Result< impl Report > { - let table_name = args.get_owned::< String >( 0 ); - - // let mut manager = FeedManager::new( storage ); let mut table_names = Vec::new(); if let Some( name ) = table_name { @@ -27,7 +24,7 @@ pub async fn table_list { let tables = storage.tables_list().await?; - let names = tables.tables.keys().map( | k | k.clone() ).collect::< Vec< _ > >(); + let names = tables.0.keys().map( | k | k.clone() ).collect::< Vec< _ > >(); table_names.extend( names.into_iter() ); } @@ -123,21 +120,24 @@ pub async fn table_list }, "authors" => { - columns_desc.insert( + columns_desc.insert + ( label.clone(), String::from( "List of authors of the frame, optional." ) ); }, "content" => { - columns_desc.insert( + columns_desc.insert + ( label.clone(), String::from( "The content of the frame in html or plain text, optional." ), ); }, "links" => { - columns_desc.insert( + columns_desc.insert + ( label.clone(), String::from( "List of links associated with this item of related Web page and attachments." ), ); @@ -232,11 +232,7 @@ pub async fn table_list } /// Get information about tables in storage. -pub async fn tables_list -( - mut storage : FeedStorage< gluesql::sled_storage::SledStorage >, - _args : &wca::Args, -) -> Result< impl Report > +pub async fn tables_list( mut storage : FeedStorage< gluesql::sled_storage::SledStorage > ) -> Result< impl Report > { storage.tables_list().await } @@ -245,7 +241,7 @@ const EMPTY_CELL : &'static str = ""; /// Information about execution of table columns commands. #[ derive( Debug ) ] -pub struct TablesColumnsReport( Vec< ColumnsReport > ); +pub struct TablesColumnsReport( pub Vec< ColumnsReport > ); impl std::fmt::Display for TablesColumnsReport { @@ -262,7 +258,7 @@ impl std::fmt::Display for TablesColumnsReport impl Report for TablesColumnsReport {} -/// Information about execution of columns commands. +/// Information about execution of columns listing action. #[ derive( Debug ) ] pub struct ColumnsReport { @@ -336,11 +332,9 @@ impl std::fmt::Display for ColumnsReport impl Report for ColumnsReport {} /// Information about execution of tables commands. +/// Contains tables name, description and list of columns. #[ derive( Debug ) ] -pub struct TablesReport -{ - tables : std::collections::HashMap< String, ( String, Vec< String > ) > -} +pub struct TablesReport( pub HashMap< String, ( String, Vec< String > ) > ); impl TablesReport { @@ -348,9 +342,8 @@ impl TablesReport pub fn new( payload : Vec< Payload > ) -> Self { let mut result = std::collections::HashMap::new(); - match &payload[ 0 ] + if let Payload::Select { labels: _label_vec, rows: rows_vec } = &payload[ 0 ] { - Payload::Select { labels: _label_vec, rows: rows_vec } => { for row in rows_vec { @@ -367,10 +360,9 @@ impl TablesReport .or_insert( ( table_description, vec![ String::from( row[ 1 ].clone() ) ] ) ) ; } - }, - _ => {}, + } } - TablesReport{ tables : result } + TablesReport( result ) } } @@ -380,7 +372,7 @@ impl std::fmt::Display for TablesReport { writeln!( f, "Storage tables:" )?; let mut rows = Vec::new(); - for ( table_name, ( desc, columns ) ) in &self.tables + for ( table_name, ( desc, columns ) ) in &self.0 { let columns_str = if !columns.is_empty() { @@ -409,7 +401,7 @@ impl std::fmt::Display for TablesReport [ EMPTY_CELL.to_owned(), "name".to_owned(), - "description".to_owned(), + "description".to_owned(), "columns".to_owned(), ], rows, diff --git a/module/move/unitore/src/command/config.rs b/module/move/unitore/src/command/config.rs index 37bbfb7aaf..72eb063007 100644 --- a/module/move/unitore/src/command/config.rs +++ b/module/move/unitore/src/command/config.rs @@ -1,5 +1,7 @@ //! Config files commands. +use std::path::PathBuf; + use crate::*; use gluesql::sled_storage::sled::Config; use wca::{ Command, Type, VerifiedCommand }; @@ -37,25 +39,35 @@ impl ConfigCommand .subject().hint( "Path" ).kind( Type::Path ).optional( false ).end() .routine( move | o : VerifiedCommand | { - let res = rt.block_on( async move - { - let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) - .unwrap_or( String::from( "./_data" ) ) - ; - - let config = Config::default() - .path( path_to_storage ) - ; - - let feed_storage = FeedStorage::init_storage( &config ).await?; - config_add( feed_storage, &o.args ).await - }); + let path_arg = o.args + .get_owned::< wca::Value >( 0 ); + + if let Some( path ) = path_arg + { + let path : PathBuf = path.into(); + + let res = rt.block_on + ( async move + { + let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) + .unwrap_or( String::from( "./_data" ) ) + ; + + let config = Config::default() + .path( path_to_storage ) + ; + + let feed_storage = FeedStorage::init_storage( &config ).await?; + config_add( feed_storage, &path ).await + } + ); + match res { Ok( report ) => report.report(), Err( err ) => println!( "{:?}", err ), } - + } }) .end() ) @@ -76,27 +88,37 @@ impl ConfigCommand )) .subject().hint( "Path" ).kind( Type::Path ).optional( false ).end() .routine( move | o : VerifiedCommand | - { - let res = rt.block_on( async move - { - let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) - .unwrap_or( String::from( "./_data" ) ) - ; - - let config = Config::default() - .path( path_to_storage ) - ; + { + let path_arg = o.args + .get_owned::< wca::Value >( 0 ); - let feed_storage = FeedStorage::init_storage( &config ).await?; - config_delete( feed_storage, &o.args ).await - }); - match res + if let Some( path ) = path_arg { - Ok( report ) => report.report(), - Err( err ) => println!( "{:?}", err ), + let path : PathBuf = path.into(); + + let res = rt.block_on + ( async move + { + let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) + .unwrap_or( String::from( "./_data" ) ) + ; + + let config = Config::default() + .path( path_to_storage ) + ; + + let feed_storage = FeedStorage::init_storage( &config ).await?; + config_delete( feed_storage, &path ).await + } + ); + + match res + { + Ok( report ) => report.report(), + Err( err ) => println!( "{:?}", err ), + } } - - }) + }) .end() ) } diff --git a/module/move/unitore/src/command/feed.rs b/module/move/unitore/src/command/feed.rs index 9255dbf3a4..148d404952 100644 --- a/module/move/unitore/src/command/feed.rs +++ b/module/move/unitore/src/command/feed.rs @@ -16,7 +16,6 @@ impl FeedCommand /// Create command that lists all feeds in storage. pub fn list() -> Result< Command > { - let rt = tokio::runtime::Runtime::new()?; Ok @@ -28,7 +27,7 @@ impl FeedCommand "List all feeds from storage.\n", " Example: .feeds.list", )) - .routine( move | o : VerifiedCommand | + .routine( move | _o : VerifiedCommand | { let res = rt.block_on( async move { @@ -41,7 +40,7 @@ impl FeedCommand ; let feed_storage = FeedStorage::init_storage( &config ).await?; - feeds_list( feed_storage, &o.args ).await + feeds_list( feed_storage ).await }); match res { diff --git a/module/move/unitore/src/command/frame.rs b/module/move/unitore/src/command/frame.rs index bdfe0d1174..8a4f18a756 100644 --- a/module/move/unitore/src/command/frame.rs +++ b/module/move/unitore/src/command/frame.rs @@ -27,7 +27,7 @@ impl FrameCommand "List all frames saved in storage.\n", " Example: .frames.list", )) - .routine( move | o : VerifiedCommand | + .routine( move | _o : VerifiedCommand | { let res = rt.block_on( async move { @@ -40,7 +40,7 @@ impl FrameCommand ; let feed_storage = FeedStorage::init_storage( &config ).await?; - frames_list( feed_storage, &o.args ).await + frames_list( feed_storage ).await }); match res { @@ -67,7 +67,7 @@ impl FrameCommand "Download frames from feed sources provided in config files.\n", " Example: .frames.download", )) - .routine( move | o : VerifiedCommand | + .routine( move | _o : VerifiedCommand | { let res = rt.block_on( async move { @@ -80,7 +80,7 @@ impl FrameCommand ; let feed_storage = FeedStorage::init_storage( &config ).await?; - frames_download( feed_storage, &o.args ).await + frames_download( feed_storage ).await }); match res { diff --git a/module/move/unitore/src/command/query.rs b/module/move/unitore/src/command/query.rs index b9ebbd67c5..24519e1a86 100644 --- a/module/move/unitore/src/command/query.rs +++ b/module/move/unitore/src/command/query.rs @@ -24,36 +24,45 @@ impl QueryCommand .phrase( "query.execute" ) .long_hint( concat! ( - "Execute custom query. Subject: query string, with special characters escaped.\n", + "Execute custom query. Subject: query string.\n", " Example query:\n", " - select all frames:\n", - r#" .query.execute \'SELECT \* FROM frame\'"#, + r#" .query.execute 'SELECT * FROM frame'"#, "\n", " - select title and link to the most recent frame:\n", - r#" .query.execute \'SELECT title, links, MIN\(published\) FROM frame\'"#, + r#" .query.execute 'SELECT title, links, MIN( published ) FROM frame'"#, "\n\n", )) .subject().hint( "Query" ).kind( Type::String ).optional( false ).end() .routine( move | o : VerifiedCommand | { - let res = rt.block_on( async move - { - let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) - .unwrap_or( String::from( "./_data" ) ) - ; - - let config = Config::default() - .path( path_to_storage ) - ; - - let feed_storage = FeedStorage::init_storage( &config ).await?; - query_execute( feed_storage, &o.args ).await - }); + let query_arg = o.args + .get_owned::< String >( 0 ) + ; + + if let Some( query_str ) = query_arg + { + let res = rt.block_on + ( async move + { + let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) + .unwrap_or( String::from( "./_data" ) ) + ; + + let config = Config::default() + .path( path_to_storage ) + ; + + let feed_storage = FeedStorage::init_storage( &config ).await?; + query_execute( feed_storage, query_str ).await + } + ); match res { Ok( report ) => report.report(), Err( err ) => println!( "{:?}", err ), } + } }) .end() diff --git a/module/move/unitore/src/command/table.rs b/module/move/unitore/src/command/table.rs index 34db044668..67c82f23a0 100644 --- a/module/move/unitore/src/command/table.rs +++ b/module/move/unitore/src/command/table.rs @@ -30,6 +30,8 @@ impl TableCommand .subject().hint( "Path" ).kind( Type::Path ).optional( false ).end() .routine( move | o : VerifiedCommand | { + let table_name_arg = o.args.get_owned::< String >( 0 ); + let res = rt.block_on( async move { let path_to_storage = std::env::var( "UNITORE_STORAGE_PATH" ) @@ -41,7 +43,7 @@ impl TableCommand ; let feed_storage = FeedStorage::init_storage( &config ).await?; - table_list( feed_storage, &o.args ).await + table_list( feed_storage, table_name_arg ).await } ); match res { @@ -76,7 +78,7 @@ impl TablesCommand " Example: .config.delete ./config/feeds.toml", )) .subject().hint( "Path" ).kind( Type::Path ).optional( false ).end() - .routine( move | o : VerifiedCommand | + .routine( move | _o : VerifiedCommand | { let res = rt.block_on( async move { @@ -89,7 +91,7 @@ impl TablesCommand ; let feed_storage = FeedStorage::init_storage( &config ).await?; - tables_list( feed_storage, &o.args ).await + tables_list( feed_storage ).await } ); match res { diff --git a/module/move/unitore/src/sled_adapter/frame.rs b/module/move/unitore/src/sled_adapter/frame.rs index 666db0921f..e2224f4958 100644 --- a/module/move/unitore/src/sled_adapter/frame.rs +++ b/module/move/unitore/src/sled_adapter/frame.rs @@ -75,7 +75,20 @@ impl FrameStore for FeedStorage< SledStorage > .insert() .columns ( - self.frame_fields.iter().map( | field | field[ 0 ] ).join( "," ).as_str() + "id, + title, + stored_time, + authors, + content, + links, + summary, + categories, + published, + source, + rights, + media, + language, + feed_link" ) .values( entries_rows ) .execute( &mut *self.storage.lock().await ) diff --git a/module/move/unitore/src/sled_adapter/mod.rs b/module/move/unitore/src/sled_adapter/mod.rs index ff73740de2..511d866e8e 100644 --- a/module/move/unitore/src/sled_adapter/mod.rs +++ b/module/move/unitore/src/sled_adapter/mod.rs @@ -27,8 +27,6 @@ pub struct FeedStorage< S : GStore + GStoreMut + Send > { /// GlueSQL storage. pub storage : Arc< Mutex< Glue< S > > >, - /// Frame table fields with description. - pub frame_fields : Vec< [ &'static str; 3 ] >, } impl< S : GStore + GStoreMut + Send > std::fmt::Debug for FeedStorage< S > @@ -50,13 +48,13 @@ impl FeedStorage< SledStorage > let mut glue = Glue::new( storage ); - let sub_table = table( "config" ) + let config_table = table( "config" ) .create_table_if_not_exists() .add_column( "path TEXT PRIMARY KEY" ) .build()? ; - sub_table.execute( &mut glue ).await?; + config_table.execute( &mut glue ).await?; let feed_table = table( "feed" ) .create_table_if_not_exists() @@ -74,37 +72,28 @@ impl FeedStorage< SledStorage > feed_table.execute( &mut glue ).await?; - let frame_fields = vec! - [ - [ "id", "TEXT", "A unique identifier for this frame in the feed. " ], - [ "title", "TEXT", "Title of the frame" ], - [ "stored_time", "TIMESTAMP", "Time at which this item was fetched from source." ], - [ "authors", "LIST", "List of authors of the frame, optional." ], - [ "content", "TEXT", "The content of the frame in html or plain text, optional." ], - [ "links", "LIST", "List of links associated with this item of related Web page and attachments." ], - [ "summary", "TEXT", "Short summary, abstract, or excerpt of the frame item, optional." ], - [ "categories", "LIST", "Specifies a list of categories that the item belongs to." ], - [ "published", "TIMESTAMP", "Time at which this item was first published or updated." ], - [ "source", "TEXT", "Specifies the source feed if the frame was copied from one feed into another feed, optional." ], - [ "rights", "TEXT", "Conveys information about copyrights over the feed, optional." ], - [ "media", "LIST", "List of media oblects, encountered in the frame, optional." ], - [ "language", "TEXT", "The language specified on the item, optional." ], - [ "feed_link", "TEXT", "Link of feed that contains this frame." ], - ]; - let mut table = table( "frame" ).create_table_if_not_exists().add_column( "id TEXT PRIMARY KEY" ); - - for column in frame_fields.iter().skip( 1 ).take( frame_fields.len() - 2 ) - { - table = table.add_column( format!( "{} {}", column[ 0 ], column[ 1 ] ).as_str() ); - } - - let table = table.add_column( "feed_link TEXT FOREIGN KEY REFERENCES feed(link)" ) + let frame_table = table( "frame" ) + .create_table_if_not_exists() + .add_column( "id TEXT PRIMARY KEY" ) + .add_column( "title TEXT" ) + .add_column( "stored_time TIMESTAMP" ) + .add_column( "authors LIST" ) + .add_column( "content TEXT" ) + .add_column( "links LIST" ) + .add_column( "summary TEXT" ) + .add_column( "categories LIST" ) + .add_column( "published TIMESTAMP" ) + .add_column( "source TEXT" ) + .add_column( "rights TEXT" ) + .add_column( "media LIST" ) + .add_column( "language TEXT" ) + .add_column( "feed_link TEXT FOREIGN KEY REFERENCES feed(link)" ) .build()? ; - table.execute( &mut glue ).await?; + frame_table.execute( &mut glue ).await?; - Ok( Self{ storage : Arc::new( Mutex::new( glue ) ), frame_fields } ) + Ok( Self{ storage : Arc::new( Mutex::new( glue ) ) } ) } } diff --git a/module/move/unitore/tests/config.rs b/module/move/unitore/tests/config.rs deleted file mode 100644 index d56c4fdfdc..0000000000 --- a/module/move/unitore/tests/config.rs +++ /dev/null @@ -1,70 +0,0 @@ -use std::path::PathBuf; -use gluesql:: -{ - sled_storage::sled::Config, - prelude::Payload::Select, -}; -use unitore:: -{ - sled_adapter::FeedStorage, - entity::{ feed::FeedStore, config::ConfigStore }, - action::config, -}; -use error_tools::Result; - -#[ tokio::test ] -async fn config_add() -> Result< () > -{ - let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); - - let config = Config::default() - .path( "./test_add".to_owned() ) - .temporary( true ) - ; - - let mut feed_storage = FeedStorage::init_storage( &config ).await?; - config::config_add( feed_storage.clone(), &wca::Args( vec![ wca::Value::Path( path ) ] ) ).await?; - - let res = feed_storage.feeds_list().await?; - - let feeds_links = res.0.selected_rows - .iter() - .map( | feed | String::from( feed[ 1 ].clone() ) ) - .collect::< Vec< _ > >() - ; - - assert!( feeds_links.len() == 2 ); - assert!( feeds_links.contains( &format!( "https://feeds.bbci.co.uk/news/world/rss.xml" ) ) ); - assert!( feeds_links.contains( &format!( "https://rss.nytimes.com/services/xml/rss/nyt/World.xml" ) ) ); - - Ok( () ) -} - -#[ tokio::test ] -async fn config_delete() -> Result< () > -{ - let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); - - let config = Config::default() - .path( "./test_del".to_owned() ) - .temporary( true ) - ; - - let mut feed_storage = FeedStorage::init_storage( &config ).await?; - config::config_add( feed_storage.clone(), &wca::Args( vec![ wca::Value::Path( path.clone() ) ] ) ).await?; - - config::config_delete( feed_storage.clone(), &wca::Args( vec![ wca::Value::Path( path ) ] ) ).await?; - - let list = feed_storage.config_list().await?; - - if let Select{ labels : _, rows } = list - { - assert!( rows.len() == 0 ) - } - else - { - assert!( false ); - } - - Ok( () ) -} diff --git a/module/move/unitore/tests/config_add.rs b/module/move/unitore/tests/config_add.rs new file mode 100644 index 0000000000..a3de7479b7 --- /dev/null +++ b/module/move/unitore/tests/config_add.rs @@ -0,0 +1,37 @@ +use std::path::PathBuf; +use gluesql::sled_storage::sled::Config; +use unitore:: +{ + sled_adapter::FeedStorage, + entity::feed::FeedStore, + action::config, +}; +use error_tools::Result; + +#[ tokio::test ] +async fn config_add() -> Result< () > +{ + let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); + + let config = Config::default() + .path( "./test_add".to_owned() ) + .temporary( true ) + ; + + let mut feed_storage = FeedStorage::init_storage( &config ).await?; + config::config_add( feed_storage.clone(), &path ).await?; + + let res = feed_storage.feeds_list().await?; + + let feeds_links = res.0.selected_rows + .iter() + .map( | feed | String::from( feed[ 1 ].clone() ) ) + .collect::< Vec< _ > >() + ; + + assert!( feeds_links.len() == 2 ); + assert!( feeds_links.contains( &format!( "https://feeds.bbci.co.uk/news/world/rss.xml" ) ) ); + assert!( feeds_links.contains( &format!( "https://rss.nytimes.com/services/xml/rss/nyt/World.xml" ) ) ); + + Ok( () ) +} diff --git a/module/move/unitore/tests/config_delete.rs b/module/move/unitore/tests/config_delete.rs new file mode 100644 index 0000000000..95870d4700 --- /dev/null +++ b/module/move/unitore/tests/config_delete.rs @@ -0,0 +1,42 @@ +use std::path::PathBuf; +use gluesql:: +{ + sled_storage::sled::Config, + prelude::Payload::Select, +}; +use unitore:: +{ + sled_adapter::FeedStorage, + entity::config::ConfigStore, + action::config, +}; +use error_tools::Result; + +#[ tokio::test ] +async fn config_delete() -> Result< () > +{ + let path = PathBuf::from( "./tests/fixtures/test_config.toml" ); + + let config = Config::default() + .path( "./test_del".to_owned() ) + .temporary( true ) + ; + + let mut feed_storage = FeedStorage::init_storage( &config ).await?; + config::config_add( feed_storage.clone(), &path ).await?; + + config::config_delete( feed_storage.clone(), &path ).await?; + + let list = feed_storage.config_list().await?; + + if let Select{ labels : _, rows } = list + { + assert!( rows.len() == 0 ) + } + else + { + assert!( false ); + } + + Ok( () ) +} diff --git a/module/move/unitore/tests/table_list.rs b/module/move/unitore/tests/table_list.rs new file mode 100644 index 0000000000..dc840b3633 --- /dev/null +++ b/module/move/unitore/tests/table_list.rs @@ -0,0 +1,45 @@ +use gluesql:: +{ + sled_storage::sled::Config, + prelude::{ Payload, Value::Str }, +}; +use unitore:: +{ + sled_adapter::FeedStorage, + entity::table::TableStore, +}; +use error_tools::Result; + +#[ tokio::test ] +async fn table_list() -> Result< () > +{ + let config = Config::default() + .path( "./test_list".to_owned() ) + .temporary( true ) + ; + 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 ] + { + let column_names = rows + .iter() + .map( | row | row[ 1 ].clone() ) + .collect::< Vec< _ > >() + ; + + assert_eq!( column_names.len(), 9 ); + assert!( column_names.contains( &Str( String::from( "published") ) ) ); + assert!( column_names.contains( &Str( String::from( "authors") ) ) ); + assert!( column_names.contains( &Str( String::from( "description") ) ) ); + assert!( column_names.contains( &Str( String::from( "type") ) ) ); + assert!( column_names.contains( &Str( String::from( "title") ) ) ); + assert!( column_names.contains( &Str( String::from( "updated") ) ) ); + assert!( column_names.contains( &Str( String::from( "link") ) ) ); + assert!( column_names.contains( &Str( String::from( "update_period" ) ) ) ); + assert!( column_names.contains( &Str( String::from( "config_file" ) ) ) ); + } + + Ok( () ) +} diff --git a/module/move/unitore/tests/tables_list.rs b/module/move/unitore/tests/tables_list.rs new file mode 100644 index 0000000000..6b306b1c19 --- /dev/null +++ b/module/move/unitore/tests/tables_list.rs @@ -0,0 +1,32 @@ +use gluesql::sled_storage::sled::Config; +use unitore:: +{ + sled_adapter::FeedStorage, + entity::table::TableStore, +}; +use error_tools::Result; + +#[ tokio::test ] +async fn tables_list() -> Result< () > +{ + let config = Config::default() + .path( "./test_list".to_owned() ) + .temporary( true ) + ; + + let mut feed_storage = FeedStorage::init_storage( &config ).await?; + let res = feed_storage.tables_list().await?; + + let table_names = res.0 + .iter() + .map( | ( table_name, _info ) | table_name ) + .collect::< Vec< _ > >() + ; + + assert_eq!( table_names.len(), 3 ); + assert!( table_names.contains( &&String::from( "config") ) ); + assert!( table_names.contains( &&String::from( "feed" ) ) ); + assert!( table_names.contains( &&String::from( "frame" ) ) ); + + Ok( () ) +}