Skip to content

Commit

Permalink
remove generator check in all templates variation
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad committed Dec 26, 2024
1 parent e4b1091 commit c62d07e
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/templates/db.rs
expression: "format!(\"{:#?}\",\nassertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())"
snapshot_kind: text
---
Mapping {
"uri": Mapping {
Expand Down Expand Up @@ -37,5 +36,5 @@ Mapping {
},
"auto_migrate": Bool(true),
"dangerously_truncate": Bool(true),
"dangerously_recreate": Bool(false),
"dangerously_recreate": Bool(true),
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/templates/db.rs
expression: "format!(\"{:#?}\",\nassertion::yaml::get_value_at_path(&content, &[\"database\"]).unwrap())"
snapshot_kind: text
---
Mapping {
"uri": Mapping {
Expand Down Expand Up @@ -37,5 +36,5 @@ Mapping {
},
"auto_migrate": Bool(true),
"dangerously_truncate": Bool(true),
"dangerously_recreate": Bool(false),
"dangerously_recreate": Bool(true),
}
228 changes: 124 additions & 104 deletions loco-new/tests/wizard/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,55 @@ fn test_all_combinations(
#[values(AssetsOption::Serverside, AssetsOption::Clientside, AssetsOption::None)]
asset: AssetsOption,
) {
test_combination(db, background, asset);
test_combination(db, background, asset, false);
}

// when running locally set LOCO_DEV_MODE_PATH=<to local loco path>
#[test]
fn test_starter_combinations() {
// lightweight service
test_combination(DBOption::None, BackgroundOption::None, AssetsOption::None);
test_combination(
DBOption::None,
BackgroundOption::None,
AssetsOption::None,
true,
);
// REST API
test_combination(
DBOption::Sqlite,
BackgroundOption::Async,
AssetsOption::None,
true,
);
// SaaS, serverside
test_combination(
DBOption::Sqlite,
BackgroundOption::Async,
AssetsOption::Serverside,
true,
);
// SaaS, clientside
test_combination(
DBOption::Sqlite,
BackgroundOption::Async,
AssetsOption::Clientside,
true,
);
// test only DB
test_combination(DBOption::Sqlite, BackgroundOption::None, AssetsOption::None);
test_combination(
DBOption::Sqlite,
BackgroundOption::None,
AssetsOption::None,
true,
);
}

fn test_combination(db: DBOption, background: BackgroundOption, asset: AssetsOption) {
fn test_combination(
db: DBOption,
background: BackgroundOption,
asset: AssetsOption,
test_generator: bool,
) {
let test_dir = tree_fs::TreeBuilder::default().drop(true);

let executor = FileSystem::new(&PathBuf::from("base_template"), &test_dir.root);
Expand Down Expand Up @@ -83,119 +101,121 @@ fn test_combination(db: DBOption, background: BackgroundOption, asset: AssetsOpt
.run_test()
.expect("run test after create new project");

// Generate API controller
tester.run_generate(&vec![
"controller",
"notes_api",
"--api",
"create_note",
"get_note",
]);

// Generate HTMX controller
tester.run_generate(&vec![
"controller",
"notes_htmx",
"--htmx",
"create_note",
"get_note",
]);

// Generate HTML controller
tester.run_generate(&vec![
"controller",
"notes_html",
"--html",
"create_note",
"get_note",
]);

// Generate Task
tester.run_generate(&vec!["task", "list_users"]);

// Generate Scheduler
tester.run_generate(&vec!["scheduler"]);

if background.enable() {
// Generate Worker
tester.run_generate(&vec!["worker", "cleanup"]);
}

if settings.mailer {
// Generate Mailer
tester.run_generate(&vec!["mailer", "user_mailer"]);
}

// Generate deployment nginx
tester.run_generate(&vec!["deployment", "--kind", "nginx"]);

// Generate deployment nginx
tester.run_generate(&vec!["deployment", "--kind", "docker"]);

if db.enable() {
// Generate Model
if !settings.auth {
tester.run_generate(&vec!["model", "users", "name:string", "email:string"]);
}
tester.run_generate(&vec!["model", "movies", "title:string", "user:references"]);

// Generate HTMX Scaffold
if test_generator {
// Generate API controller
tester.run_generate(&vec![
"scaffold",
"movies_htmx",
"title:string",
"user:references",
"--htmx",
"controller",
"notes_api",
"--api",
"create_note",
"get_note",
]);

// Generate HTML Scaffold
// Generate HTMX controller
tester.run_generate(&vec![
"scaffold",
"movies_html",
"title:string",
"user:references",
"--html",
"controller",
"notes_htmx",
"--htmx",
"create_note",
"get_note",
]);

// Generate API Scaffold
// Generate HTML controller
tester.run_generate(&vec![
"scaffold",
"movies_api",
"title:string",
"user:references",
"--api",
"controller",
"notes_html",
"--html",
"create_note",
"get_note",
]);

// Generate CreatePosts migration
tester.run_generate_migration(&vec![
"CreatePosts",
"title:string",
"user:references",
"movies:references",
]);
// Generate Task
tester.run_generate(&vec!["task", "list_users"]);

// Generate AddNameAndAgeToUsers migration
tester.run_generate_migration(&vec![
"AddNameAndAgeToUsers",
"first_name:string",
"age:int",
]);
// Generate Scheduler
tester.run_generate(&vec!["scheduler"]);

// Generate AddNameAndAgeToUsers migration
tester.run_generate_migration(&vec![
"RemoveNameAndAgeFromUsers",
"first_name:string",
"age:int",
]);
if background.enable() {
// Generate Worker
tester.run_generate(&vec!["worker", "cleanup"]);
}

// Generate AddUserRefToPosts migration
// TODO:: not working on sqlite.
// - thread 'main' panicked at 'Sqlite doesn't support multiple alter options'
// - Sqlite does not support modification of foreign key constraints to existing
// tester.run_generate_migration(&vec!["AddUserRefToPosts", "movies:references"]);
if settings.mailer {
// Generate Mailer
tester.run_generate(&vec!["mailer", "user_mailer"]);
}

// Generate CreateJoinTableUsersAndGroups migration
tester.run_generate_migration(&vec!["CreateJoinTableUsersAndGroups", "count:int"]);
// Generate deployment nginx
tester.run_generate(&vec!["deployment", "--kind", "nginx"]);

// Generate deployment nginx
tester.run_generate(&vec!["deployment", "--kind", "docker"]);

if db.enable() {
// Generate Model
if !settings.auth {
tester.run_generate(&vec!["model", "users", "name:string", "email:string"]);
}
tester.run_generate(&vec!["model", "movies", "title:string", "user:references"]);

// Generate HTMX Scaffold
tester.run_generate(&vec![
"scaffold",
"movies_htmx",
"title:string",
"user:references",
"--htmx",
]);

// Generate HTML Scaffold
tester.run_generate(&vec![
"scaffold",
"movies_html",
"title:string",
"user:references",
"--html",
]);

// Generate API Scaffold
tester.run_generate(&vec![
"scaffold",
"movies_api",
"title:string",
"user:references",
"--api",
]);

// Generate CreatePosts migration
tester.run_generate_migration(&vec![
"CreatePosts",
"title:string",
"user:references",
"movies:references",
]);

// Generate AddNameAndAgeToUsers migration
tester.run_generate_migration(&vec![
"AddNameAndAgeToUsers",
"first_name:string",
"age:int",
]);

// Generate AddNameAndAgeToUsers migration
tester.run_generate_migration(&vec![
"RemoveNameAndAgeFromUsers",
"first_name:string",
"age:int",
]);

// Generate AddUserRefToPosts migration
// TODO:: not working on sqlite.
// - thread 'main' panicked at 'Sqlite doesn't support multiple alter options'
// - Sqlite does not support modification of foreign key constraints to existing
// tester.run_generate_migration(&vec!["AddUserRefToPosts", "movies:references"]);

// Generate CreateJoinTableUsersAndGroups migration
tester.run_generate_migration(&vec!["CreateJoinTableUsersAndGroups", "count:int"]);
}
}
}

Expand Down

0 comments on commit c62d07e

Please sign in to comment.