From c2db99352db95af4040c4ed57a54a8e074a94cbe Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Tue, 21 Jan 2025 15:50:35 +0800 Subject: [PATCH] fix unit tests --- templates/classic/_base/config.toml.liquid | 10 +++++----- templates/classic/_base/src/main.rs.liquid | 6 ++++-- templates/classic/_base/src/routers/demo.rs | 20 +------------------- templates/classic/rbatis/src/routers/demo.rs | 20 +------------------- 4 files changed, 11 insertions(+), 45 deletions(-) diff --git a/templates/classic/_base/config.toml.liquid b/templates/classic/_base/config.toml.liquid index c853a05..f3dee1f 100644 --- a/templates/classic/_base/config.toml.liquid +++ b/templates/classic/_base/config.toml.liquid @@ -3,18 +3,18 @@ listen_addr = "127.0.0.1:8008" [db] {%- if db_type == "postgres" %} url = "postgres://postgres:root@127.0.0.1:5432/{{project_name}}" -{%- endif %} -{%- if db_type == "sqlite" %} +{%- elsif db_type == "sqlite" %} {%- if db_lib == "seaorm" %} url = "sqlite:./data/{{db_lib}}.sqlite" {%- else %} url = "file:./data/{{db_lib}}.sqlite" {%- endif %} -{%- endif %} -{%- if db_type == "mysql" %} +{%- elsif db_type == "mysql" %} url = "mysql://root:root@localhost/{{project_name}}" +{%- elsif db_type == "mongodb" %} +url = "mongodb://root:root@localhost:27017" +database = "{{project_name}}" {%- endif %} -pool_size = 1 [jwt] secret = "yoursecret" diff --git a/templates/classic/_base/src/main.rs.liquid b/templates/classic/_base/src/main.rs.liquid index 5d6085d..64cd621 100644 --- a/templates/classic/_base/src/main.rs.liquid +++ b/templates/classic/_base/src/main.rs.liquid @@ -121,11 +121,13 @@ mod tests { #[tokio::test] async fn test_hello_world() { - let service = Service::new(super::router()); + config::init(); + + let service = Service::new(crate::routers::root()); let content = TestClient::get(format!( "http://{}", - &config::get().address.replace("0.0.0.0", "127.0.0.1") + config::get().listen_addr.replace("0.0.0.0", "127.0.0.1") )) .send(&service) .await diff --git a/templates/classic/_base/src/routers/demo.rs b/templates/classic/_base/src/routers/demo.rs index 2e91031..591af38 100644 --- a/templates/classic/_base/src/routers/demo.rs +++ b/templates/classic/_base/src/routers/demo.rs @@ -14,22 +14,4 @@ pub async fn hello(req: &mut Request) -> AppResult> { name: req.query::<&str>("name").unwrap_or("World"), }; Ok(Text::Html(hello_tmpl.render().unwrap())) -} - -mod tests { - #[tokio::test] - async fn test_hello_world() { - let service = Service::new(crate::routers::router()); - - let content = TestClient::get(format!( - "http://{}", - &config.listen_addr.replace("0.0.0.0", "127.0.0.1") - )) - .send(&service) - .await - .take_string() - .await - .unwrap(); - assert_eq!(content, "Hello World from salvo"); - } -} +} \ No newline at end of file diff --git a/templates/classic/rbatis/src/routers/demo.rs b/templates/classic/rbatis/src/routers/demo.rs index 2e91031..591af38 100644 --- a/templates/classic/rbatis/src/routers/demo.rs +++ b/templates/classic/rbatis/src/routers/demo.rs @@ -14,22 +14,4 @@ pub async fn hello(req: &mut Request) -> AppResult> { name: req.query::<&str>("name").unwrap_or("World"), }; Ok(Text::Html(hello_tmpl.render().unwrap())) -} - -mod tests { - #[tokio::test] - async fn test_hello_world() { - let service = Service::new(crate::routers::router()); - - let content = TestClient::get(format!( - "http://{}", - &config.listen_addr.replace("0.0.0.0", "127.0.0.1") - )) - .send(&service) - .await - .take_string() - .await - .unwrap(); - assert_eq!(content, "Hello World from salvo"); - } -} +} \ No newline at end of file