From d541099330a63978061f93538dafa0fc14187e58 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 16:03:51 +0300 Subject: [PATCH 1/9] move task args from BTreeMap to struct --- docs-site/content/docs/the-app/task.md | 40 ++++++++++++----- examples/demo/examples/task.rs | 5 ++- examples/demo/src/tasks/foo.rs | 8 ++-- examples/demo/src/tasks/seed.rs | 8 ++-- examples/demo/src/tasks/user_report.rs | 4 +- examples/demo/tests/tasks/foo.rs | 24 +++++----- examples/demo/tests/tasks/mod.rs | 1 + examples/demo/tests/tasks/seed.rs | 18 ++++---- snipdoc.yml | 9 ++++ src/boot.rs | 6 +-- src/cli.rs | 11 ++--- src/prelude.rs | 2 +- src/task.rs | 62 +++++++++++++++++++++++--- 13 files changed, 132 insertions(+), 66 deletions(-) diff --git a/docs-site/content/docs/the-app/task.md b/docs-site/content/docs/the-app/task.md index c4e94a82d..e63eaaef2 100644 --- a/docs-site/content/docs/the-app/task.md +++ b/docs-site/content/docs/the-app/task.md @@ -30,25 +30,44 @@ Each task is designed to parse command-line arguments into flags, utilizing the Generate the task: + ```sh -$ cargo loco generate task [OPTIONS] +Generate a Task based on the given name + +Usage: blo-cli generate task [OPTIONS] + +Arguments: + Name of the thing to generate + +Options: + -e, --environment Specify the environment [default: development] + -h, --help Print help + -V, --version Print version + ``` + ## Running a Task Execute the task you created in the previous step using the following command: + ```sh -$ cargo loco task +cargo loco task ``` + + ## Listing All Tasks To view a list of all tasks that have been executed, use the following command: + ```sh -$ cargo loco task +cargo loco task ``` + + ## Creating a Task manually @@ -58,24 +77,25 @@ If you prefer a manual approach to creating tasks in `Loco`, you can follow thes Start by creating a new file under the path `src/tasks`. For example, let's create a file named `example.rs`: + ```rust -// src/tasks/example.rs +use loco_rs::prelude::*; -pub struct ExampleTask; +pub struct Foo; #[async_trait] -impl Task for ExampleTask { +impl Task for Foo { fn task(&self) -> TaskInfo { TaskInfo { - name: "example".to_string(), - detail: "Example task executed successfully".to_string(), + name: "foo".to_string(), + detail: "run foo task".to_string(), } } - async fn run(&self, app_context: &AppContext, vars: &BTreeMap) -> Result<()> { - println!("Example task executed successfully"); + async fn run(&self, _app_context: &AppContext, _vars: &task::Vars) -> Result<()> { Ok(()) } } ``` + #### 2. Load the File in mod.rs diff --git a/examples/demo/examples/task.rs b/examples/demo/examples/task.rs index fd6f6dbd7..45eb37e4d 100644 --- a/examples/demo/examples/task.rs +++ b/examples/demo/examples/task.rs @@ -1,9 +1,10 @@ -use std::{collections::BTreeMap, env}; +use std::env; use blo::app::App; use loco_rs::{ boot::{create_context, run_task}, environment::{resolve_from_env, Environment}, + task, }; #[tokio::main] @@ -13,7 +14,7 @@ async fn main() -> eyre::Result<()> { let args = env::args().collect::>(); let cmd = args.get(1); let app_context = create_context::(&environment).await?; - run_task::(&app_context, cmd, &BTreeMap::new()).await?; + run_task::(&app_context, cmd, &task::Vars::default()).await?; Ok(()) } diff --git a/examples/demo/src/tasks/foo.rs b/examples/demo/src/tasks/foo.rs index a08d24cc6..43193b49d 100644 --- a/examples/demo/src/tasks/foo.rs +++ b/examples/demo/src/tasks/foo.rs @@ -1,5 +1,4 @@ -use std::collections::BTreeMap; - +// use loco_rs::prelude::*; pub struct Foo; @@ -8,10 +7,11 @@ impl Task for Foo { fn task(&self) -> TaskInfo { TaskInfo { name: "foo".to_string(), - detail: "test misaligned cli prints".to_string(), + detail: "run foo task".to_string(), } } - async fn run(&self, _app_context: &AppContext, _vars: &BTreeMap) -> Result<()> { + async fn run(&self, _app_context: &AppContext, _vars: &task::Vars) -> Result<()> { Ok(()) } } +// diff --git a/examples/demo/src/tasks/seed.rs b/examples/demo/src/tasks/seed.rs index 568383248..34227a283 100644 --- a/examples/demo/src/tasks/seed.rs +++ b/examples/demo/src/tasks/seed.rs @@ -12,8 +12,6 @@ //! command with the `refresh:true` argument: ```sh //! cargo run task seed_data refresh:true //! ``` -use std::collections::BTreeMap; - use loco_rs::{db, prelude::*}; use migration::Migrator; @@ -29,8 +27,10 @@ impl Task for SeedData { detail: "Task for seeding data".to_string(), } } - async fn run(&self, app_context: &AppContext, vars: &BTreeMap) -> Result<()> { - let refresh = vars.get("refresh").is_some_and(|refresh| refresh == "true"); + async fn run(&self, app_context: &AppContext, vars: &task::Vars) -> Result<()> { + let refresh = vars + .cli_arg("refresh") + .is_ok_and(|refresh| refresh == "true"); if refresh { db::reset::(&app_context.db).await?; diff --git a/examples/demo/src/tasks/user_report.rs b/examples/demo/src/tasks/user_report.rs index 7d814792c..4440fe404 100644 --- a/examples/demo/src/tasks/user_report.rs +++ b/examples/demo/src/tasks/user_report.rs @@ -1,5 +1,3 @@ -use std::collections::BTreeMap; - use loco_rs::prelude::*; use crate::models::_entities::users; @@ -13,7 +11,7 @@ impl Task for UserReport { detail: "output a user report".to_string(), } } - async fn run(&self, app_context: &AppContext, vars: &BTreeMap) -> Result<()> { + async fn run(&self, app_context: &AppContext, vars: &task::Vars) -> Result<()> { let users = users::Entity::find().all(&app_context.db).await?; println!("args: {vars:?}"); println!("!!! user_report: listing users !!!"); diff --git a/examples/demo/tests/tasks/foo.rs b/examples/demo/tests/tasks/foo.rs index 7d4c9d30d..8df7d6249 100644 --- a/examples/demo/tests/tasks/foo.rs +++ b/examples/demo/tests/tasks/foo.rs @@ -1,21 +1,17 @@ use blo::app::App; -use loco_rs::testing; - -use loco_rs::boot::run_task; -use migration::Migrator; +use loco_rs::{boot::run_task, task, testing}; use serial_test::serial; -use std::collections::BTreeMap; #[tokio::test] #[serial] -async fn test_can_seed_data() { - let boot = testing::boot_test::().await.unwrap(); - - let vars = BTreeMap::new(); +async fn test_can_run_foo_task() { + let boot = testing::boot_test::().await.unwrap(); - assert!( - run_task::(&boot.app_context, Some(&"foo".to_string()), &vars) - .await - .is_ok() - ); + assert!(run_task::( + &boot.app_context, + Some(&"foo".to_string()), + &task::Vars::default() + ) + .await + .is_ok()); } diff --git a/examples/demo/tests/tasks/mod.rs b/examples/demo/tests/tasks/mod.rs index 1db8d3c21..85b8d8f37 100644 --- a/examples/demo/tests/tasks/mod.rs +++ b/examples/demo/tests/tasks/mod.rs @@ -1 +1,2 @@ mod seed; +mod foo; diff --git a/examples/demo/tests/tasks/seed.rs b/examples/demo/tests/tasks/seed.rs index 43c8faee0..394b5ed5f 100644 --- a/examples/demo/tests/tasks/seed.rs +++ b/examples/demo/tests/tasks/seed.rs @@ -1,7 +1,5 @@ -use std::collections::BTreeMap; - use blo::app::App; -use loco_rs::{boot::run_task, testing}; +use loco_rs::{boot::run_task, task, testing}; use serial_test::serial; #[tokio::test] @@ -9,11 +7,11 @@ use serial_test::serial; async fn test_can_seed_data() { let boot = testing::boot_test::().await.unwrap(); - let vars = BTreeMap::new(); - - assert!( - run_task::(&boot.app_context, Some(&"seed_data".to_string()), &vars) - .await - .is_ok() - ); + assert!(run_task::( + &boot.app_context, + Some(&"seed_data".to_string()), + &task::Vars::default() + ) + .await + .is_ok()); } diff --git a/snipdoc.yml b/snipdoc.yml index 355914c62..e9787d1d6 100644 --- a/snipdoc.yml +++ b/snipdoc.yml @@ -93,3 +93,12 @@ snippets: content: cargo loco generate scaffold posts name:string title:string content:text path: ./snipdoc.yml + generate-task-help-command: + content: cd ./examples/demo && cargo loco generate task --help + path: ./snipdoc.yml + run-task-command: + content: cargo loco task + path: ./snipdoc.yml + list-tasks-command: + content: cargo loco task + path: ./snipdoc.yml diff --git a/src/boot.rs b/src/boot.rs index 9205571ba..bb6e7db9d 100644 --- a/src/boot.rs +++ b/src/boot.rs @@ -1,8 +1,6 @@ //! # Application Bootstrapping and Logic //! This module contains functions and structures for bootstrapping and running //! your application. -use std::collections::BTreeMap; - use axum::Router; #[cfg(feature = "with-db")] use sea_orm_migration::MigratorTrait; @@ -21,7 +19,7 @@ use crate::{ mailer::{EmailSender, MailerWorker}, redis, storage::{self, Storage}, - task::Tasks, + task::{self, Tasks}, worker::{self, AppWorker, Pool, Processor, RedisConnectionManager, DEFAULT_QUEUES}, Result, }; @@ -105,7 +103,7 @@ async fn process(processor: Processor) -> Result<()> { pub async fn run_task( app_context: &AppContext, task: Option<&String>, - vars: &BTreeMap, + vars: &task::Vars, ) -> Result<()> { let mut tasks = Tasks::default(); H::register_tasks(&mut tasks); diff --git a/src/cli.rs b/src/cli.rs index c7c643387..04f3bc2a0 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,9 +14,6 @@ //! cli::main::().await //! } //! ``` - -use std::collections::BTreeMap; - cfg_if::cfg_if! { if #[cfg(feature = "with-db")] { use sea_orm_migration::MigratorTrait; @@ -37,7 +34,7 @@ use crate::{ }, environment::{resolve_from_env, Environment, DEFAULT_ENVIRONMENT}, gen::{self, Component}, - logger, + logger, task, }; #[derive(Parser)] #[command(author, version, about, long_about = None)] @@ -338,12 +335,12 @@ pub async fn main() -> eyre::Result<()> { show_list_endpoints::(&app_context); } Commands::Task { name, params } => { - let mut hash = BTreeMap::new(); + let mut vars = task::Vars::default(); for (k, v) in params { - hash.insert(k, v); + vars.add_cli_arg(k, v) } let app_context = create_context::(&environment).await?; - run_task::(&app_context, name.as_ref(), &hash).await?; + run_task::(&app_context, name.as_ref(), &vars).await?; } Commands::Generate { component } => { gen::generate::(component.into(), &config)?; diff --git a/src/prelude.rs b/src/prelude.rs index 2ede634da..2fe2c1000 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -30,7 +30,7 @@ pub use crate::{ errors::Error, mailer, mailer::Mailer, - task::{Task, TaskInfo}, + task::{self, Task, TaskInfo}, validation::{self, Validatable}, validator::Validate, worker::{self, AppWorker}, diff --git a/src/task.rs b/src/task.rs index c0cc6e693..614d0b3be 100644 --- a/src/task.rs +++ b/src/task.rs @@ -8,6 +8,59 @@ use async_trait::async_trait; use crate::{app::AppContext, errors::Error, Result}; +/// Struct representing a collection of task arguments. +#[derive(Default, Debug)] +pub struct Vars { + /// A list of cli arguments. + pub cli: BTreeMap, +} + +impl Vars { + /// Adds a new key-value pair to the `cli` BTreeMap. + /// + /// # Arguments + /// + /// * `key` - A string representing the key. + /// * `value` - A string representing the value. + /// + /// # Example + /// + /// ``` + /// use loco_rs::task::Vars; + /// + /// let mut vars = Vars::default(); + /// vars.add_cli_arg("key1".to_string(), "value1".to_string()); + /// ``` + pub fn add_cli_arg(&mut self, key: String, value: String) { + self.cli.insert(key, value); + } + + /// Retrieves the value associated with the given key from the `cli` + /// BTreeMap. + /// + /// # Errors + /// + /// Returns an error if the key does not exist. + /// + /// # Example + /// + /// ``` + /// use loco_rs::task::Vars; + /// + /// let mut vars = Vars::default(); + /// vars.add_cli_arg("key1".to_string(), "value1".to_string()); + /// + /// assert!(vars.cli_arg("key1").is_ok()); + /// assert!(vars.cli_arg("not-exists").is_err()); + /// ``` + pub fn cli_arg(&self, key: &str) -> Result<&String> { + Ok(self + .cli + .get(key) + .ok_or(Error::Message(format!("The argument {key} does not exist")))?) + } +} + /// Information about a task, including its name and details. #[allow(clippy::module_name_repetitions)] pub struct TaskInfo { @@ -21,7 +74,7 @@ pub trait Task: Send + Sync { /// Get information about the task. fn task(&self) -> TaskInfo; /// Execute the task with the provided application context and variables. - async fn run(&self, app_context: &AppContext, vars: &BTreeMap) -> Result<()>; + async fn run(&self, app_context: &AppContext, vars: &Vars) -> Result<()>; } /// Managing and running tasks. @@ -43,12 +96,7 @@ impl Tasks { /// /// Returns a [`Result`] if an task finished with error. mostly if the given /// task is not found or an error to run the task.s - pub async fn run( - &self, - app_context: &AppContext, - task: &str, - vars: &BTreeMap, - ) -> Result<()> { + pub async fn run(&self, app_context: &AppContext, task: &str, vars: &Vars) -> Result<()> { let task = self .registry .get(task) From 8a7dfc0d1a3f30bb73f6341a9dc3a926d5ef8e5c Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 16:05:06 +0300 Subject: [PATCH 2/9] fmt --- examples/demo/tests/tasks/mod.rs | 2 +- loco-extras/src/initializers/mongodb/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/demo/tests/tasks/mod.rs b/examples/demo/tests/tasks/mod.rs index 85b8d8f37..716e26d52 100644 --- a/examples/demo/tests/tasks/mod.rs +++ b/examples/demo/tests/tasks/mod.rs @@ -1,2 +1,2 @@ -mod seed; mod foo; +mod seed; diff --git a/loco-extras/src/initializers/mongodb/mod.rs b/loco-extras/src/initializers/mongodb/mod.rs index a7e013c67..87564ae4e 100644 --- a/loco-extras/src/initializers/mongodb/mod.rs +++ b/loco-extras/src/initializers/mongodb/mod.rs @@ -1,7 +1,6 @@ use async_trait::async_trait; use axum::{Extension, Router as AxumRouter}; use loco_rs::prelude::*; - use mongodb::{bson::doc, options::ClientOptions, Client, Database}; #[allow(clippy::module_name_repetitions)] @@ -106,7 +105,8 @@ fn merge_config_with_client(co: &mut ClientOptions, config: MongoDbConfig) -> Cl .default_database .or(co.default_database.clone()); co.tls = client_options.tls.or(co.tls.clone()); - // co.tracing_max_document_length_bytes = client_options.tracing_max_document_length_bytes; + // co.tracing_max_document_length_bytes = + // client_options.tracing_max_document_length_bytes; co.write_concern = client_options.write_concern.or(co.write_concern.clone()); co.srv_max_hosts = client_options.srv_max_hosts.or(co.srv_max_hosts.clone()); From 1bdac283678a8639bf2b8020795b1508c2a455cf Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 16:11:29 +0300 Subject: [PATCH 3/9] clippy --- src/cli.rs | 2 +- src/task.rs | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 04f3bc2a0..704c926d9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -337,7 +337,7 @@ pub async fn main() -> eyre::Result<()> { Commands::Task { name, params } => { let mut vars = task::Vars::default(); for (k, v) in params { - vars.add_cli_arg(k, v) + vars.add_cli_arg(k, v); } let app_context = create_context::(&environment).await?; run_task::(&app_context, name.as_ref(), &vars).await?; diff --git a/src/task.rs b/src/task.rs index 614d0b3be..19b70a7b1 100644 --- a/src/task.rs +++ b/src/task.rs @@ -16,7 +16,7 @@ pub struct Vars { } impl Vars { - /// Adds a new key-value pair to the `cli` BTreeMap. + /// Adds a new key-value pair to the `cli`. /// /// # Arguments /// @@ -35,8 +35,7 @@ impl Vars { self.cli.insert(key, value); } - /// Retrieves the value associated with the given key from the `cli` - /// BTreeMap. + /// Retrieves the value associated with the given key from the `cli` list. /// /// # Errors /// @@ -54,10 +53,9 @@ impl Vars { /// assert!(vars.cli_arg("not-exists").is_err()); /// ``` pub fn cli_arg(&self, key: &str) -> Result<&String> { - Ok(self - .cli + self.cli .get(key) - .ok_or(Error::Message(format!("The argument {key} does not exist")))?) + .ok_or(Error::Message(format!("The argument {key} does not exist"))) } } From f9973cebd93509c2edf90ca903318c2b7fc03c98 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 16:30:10 +0300 Subject: [PATCH 4/9] small changes --- examples/demo/tests/cmd/cli.trycmd | 2 +- src/cli.rs | 5 +---- src/task.rs | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/demo/tests/cmd/cli.trycmd b/examples/demo/tests/cmd/cli.trycmd index fccf4cbdb..de8c5da19 100644 --- a/examples/demo/tests/cmd/cli.trycmd +++ b/examples/demo/tests/cmd/cli.trycmd @@ -72,7 +72,7 @@ Options: ```console $ LOCO_ENV=test blo-cli task -foo [test misaligned cli prints] +foo [run foo task] seed_data [Task for seeding data] user_report [output a user report] diff --git a/src/cli.rs b/src/cli.rs index 704c926d9..d7167df49 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -335,10 +335,7 @@ pub async fn main() -> eyre::Result<()> { show_list_endpoints::(&app_context); } Commands::Task { name, params } => { - let mut vars = task::Vars::default(); - for (k, v) in params { - vars.add_cli_arg(k, v); - } + let vars = task::Vars::from_cli_args(params); let app_context = create_context::(&environment).await?; run_task::(&app_context, name.as_ref(), &vars).await?; } diff --git a/src/task.rs b/src/task.rs index 19b70a7b1..af5136489 100644 --- a/src/task.rs +++ b/src/task.rs @@ -16,7 +16,7 @@ pub struct Vars { } impl Vars { - /// Adds a new key-value pair to the `cli`. + /// Create [`Vars`] instance from cli arguments. /// /// # Arguments /// @@ -28,11 +28,13 @@ impl Vars { /// ``` /// use loco_rs::task::Vars; /// - /// let mut vars = Vars::default(); - /// vars.add_cli_arg("key1".to_string(), "value1".to_string()); + /// let args = vec![("key1".to_string(), "value".to_string())]; + /// let vars = Vars::from_cli_args(args); /// ``` - pub fn add_cli_arg(&mut self, key: String, value: String) { - self.cli.insert(key, value); + pub fn from_cli_args(args: Vec<(String, String)>) -> Self { + Self { + cli: args.into_iter().collect(), + } } /// Retrieves the value associated with the given key from the `cli` list. @@ -46,8 +48,8 @@ impl Vars { /// ``` /// use loco_rs::task::Vars; /// - /// let mut vars = Vars::default(); - /// vars.add_cli_arg("key1".to_string(), "value1".to_string()); + /// let params = vec![("key1".to_string(), "value".to_string())]; + /// let vars = Vars::from_cli_args(args); /// /// assert!(vars.cli_arg("key1").is_ok()); /// assert!(vars.cli_arg("not-exists").is_err()); @@ -55,7 +57,7 @@ impl Vars { pub fn cli_arg(&self, key: &str) -> Result<&String> { self.cli .get(key) - .ok_or(Error::Message(format!("The argument {key} does not exist"))) + .ok_or(Error::Message(format!("the argument {key} does not exist"))) } } From 97253876840c46931a87a7c3f0527581d13e18e3 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 16:32:46 +0300 Subject: [PATCH 5/9] clippy --- src/task.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/task.rs b/src/task.rs index af5136489..1cdf73217 100644 --- a/src/task.rs +++ b/src/task.rs @@ -31,6 +31,7 @@ impl Vars { /// let args = vec![("key1".to_string(), "value".to_string())]; /// let vars = Vars::from_cli_args(args); /// ``` + #[must_use] pub fn from_cli_args(args: Vec<(String, String)>) -> Self { Self { cli: args.into_iter().collect(), From bc11330b0e43b794a58a8dae6c6307fa459dc20d Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 16:43:20 +0300 Subject: [PATCH 6/9] test --- src/task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/task.rs b/src/task.rs index 1cdf73217..86d482972 100644 --- a/src/task.rs +++ b/src/task.rs @@ -49,7 +49,7 @@ impl Vars { /// ``` /// use loco_rs::task::Vars; /// - /// let params = vec![("key1".to_string(), "value".to_string())]; + /// let args = vec![("key1".to_string(), "value".to_string())]; /// let vars = Vars::from_cli_args(args); /// /// assert!(vars.cli_arg("key1").is_ok()); From bfeadbabe12614e8d9623d40efae3dc354d07720 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 16:54:40 +0300 Subject: [PATCH 7/9] change generator --- src/gen/templates/task.t | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gen/templates/task.t b/src/gen/templates/task.t index 5fd93dbb3..5648434a3 100644 --- a/src/gen/templates/task.t +++ b/src/gen/templates/task.t @@ -11,8 +11,6 @@ injections: after: "fn register_tasks" content: " tasks.register(tasks::{{file_name}}::{{module_name}});" --- -use std::collections::BTreeMap; - use loco_rs::prelude::*; pub struct {{module_name}}; @@ -24,7 +22,7 @@ impl Task for {{module_name}} { detail: "Task generator".to_string(), } } - async fn run(&self, _app_context: &AppContext, _vars: &BTreeMap) -> Result<()> { + async fn run(&self, _app_context: &AppContext, _vars: &task::Vars) -> Result<()> { println!("Task {{module_name}} generated"); Ok(()) } From ac1fb129ef52f19e3408afee3733599e127febdb Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 17:07:21 +0300 Subject: [PATCH 8/9] change generator --- src/gen/templates/task_test.t | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/gen/templates/task_test.t b/src/gen/templates/task_test.t index b56021186..5d84de4f6 100644 --- a/src/gen/templates/task_test.t +++ b/src/gen/templates/task_test.t @@ -9,21 +9,18 @@ injections: content: "pub mod {{ file_name }};" --- use {{pkg_name}}::app::App; -use loco_rs::testing; +use loco_rs::{task, testing}; use loco_rs::boot::run_task; use serial_test::serial; -use std::collections::BTreeMap; #[tokio::test] #[serial] async fn test_can_run_{{name | snake_case}}() { let boot = testing::boot_test::().await.unwrap(); - let vars = BTreeMap::new(); - assert!( - run_task::(&boot.app_context, Some(&"{{name}}".to_string()), &vars) + run_task::(&boot.app_context, Some(&"{{name}}".to_string()),&task::Vars::default()) .await .is_ok() ); From 1f5a7dd96c3ffc3228b19cb301b3294d283b42c0 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 10 Jun 2024 17:07:35 +0300 Subject: [PATCH 9/9] change generator --- src/gen/templates/task_test.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gen/templates/task_test.t b/src/gen/templates/task_test.t index 5d84de4f6..171d7c519 100644 --- a/src/gen/templates/task_test.t +++ b/src/gen/templates/task_test.t @@ -20,7 +20,7 @@ async fn test_can_run_{{name | snake_case}}() { let boot = testing::boot_test::().await.unwrap(); assert!( - run_task::(&boot.app_context, Some(&"{{name}}".to_string()),&task::Vars::default()) + run_task::(&boot.app_context, Some(&"{{name}}".to_string()), &task::Vars::default()) .await .is_ok() );