-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
mod test; | ||
mod utils; | ||
use i18n::set_locale; | ||
mod i18n; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod test_write_project; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::{ | ||
utils::{ | ||
create_project::write_project_file, | ||
get_selection::{DbConnectionType, DbType, TemplateType, UserSelected}, | ||
}, | ||
Project, | ||
}; | ||
use itertools::Itertools; | ||
use std::path::Path; | ||
|
||
#[test] | ||
fn test_write_project_all_combinations() { | ||
let template_types = vec![TemplateType::SalvoWebSite, TemplateType::SalvoWebApi]; | ||
//let db_types = vec![DbType::Sqlite, DbType::Mysql, DbType::Postgres, DbType::Mssql]; | ||
let db_types = vec![DbType::Sqlite]; | ||
let db_conn_types = vec![ | ||
DbConnectionType::Sqlx, | ||
DbConnectionType::SeaOrm, | ||
DbConnectionType::Diesel, | ||
DbConnectionType::Rbatis, | ||
DbConnectionType::Mongodb, | ||
DbConnectionType::Nothing, | ||
]; | ||
|
||
// Generate all combinations | ||
let combinations = template_types | ||
.iter() | ||
.cartesian_product(db_types.iter()) | ||
.cartesian_product(db_conn_types.iter()) | ||
.map(|((template_type, db_type), db_conn_type)| (template_type, db_type, db_conn_type)) | ||
.collect::<Vec<_>>(); | ||
|
||
// Test each combination | ||
for (template_type, db_type, db_conn_type) in combinations { | ||
// Generate a unique project name for each combination | ||
let project_name = format!( | ||
"test_{}_{}_{}", | ||
format!("{:?}", template_type), | ||
format!("{:?}", db_type), | ||
format!("{:?}", db_conn_type) | ||
); | ||
|
||
let path_str = format!("target/{}", project_name); | ||
std::fs::remove_dir_all(&path_str).unwrap_or_else(|_| {}); | ||
let path = Path::new(&path_str); | ||
|
||
let user_selected = UserSelected { | ||
template_type: *template_type, | ||
db_type: *db_type, | ||
db_conn_type: *db_conn_type, | ||
}; | ||
let project = Project { | ||
project_name: project_name.clone(), | ||
lang: Some("zh".to_string()), | ||
}; | ||
match write_project_file(path, user_selected, project) { | ||
Ok(()) => { | ||
let output = std::process::Command::new("cargo") | ||
.arg("check") | ||
.current_dir(&path_str) | ||
.output() | ||
.expect("failed to execute process"); | ||
if !output.status.success() { | ||
eprintln!( | ||
"Failed on combination: template_type={:?}, db_type={:?}, db_conn_type={:?}", | ||
template_type, db_type, db_conn_type | ||
); | ||
eprintln!("Output: {:?}", output); | ||
assert!(false); | ||
} | ||
} | ||
Err(e) => { | ||
eprintln!( | ||
"Failed to write project file on combination: template_type={:?}, db_type={:?}, db_conn_type={:?}", | ||
template_type, db_type, db_conn_type | ||
); | ||
eprintln!("Error: {:?}", e); | ||
assert!(false); | ||
} | ||
} | ||
std::fs::remove_dir_all(&path_str).unwrap_or_else(|_| {}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters