Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Jan 21, 2025
1 parent 55537b1 commit c2db993
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 45 deletions.
10 changes: 5 additions & 5 deletions templates/classic/_base/config.toml.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ listen_addr = "127.0.0.1:8008"
[db]
{%- if db_type == "postgres" %}
url = "postgres://postgres:[email protected]: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"
Expand Down
6 changes: 4 additions & 2 deletions templates/classic/_base/src/main.rs.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 1 addition & 19 deletions templates/classic/_base/src/routers/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,4 @@ pub async fn hello(req: &mut Request) -> AppResult<Text<String>> {
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");
}
}
}
20 changes: 1 addition & 19 deletions templates/classic/rbatis/src/routers/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,4 @@ pub async fn hello(req: &mut Request) -> AppResult<Text<String>> {
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");
}
}
}

0 comments on commit c2db993

Please sign in to comment.