diff options
author | Melody Horn / boringcactus <melody@boringcactus.com> | 2021-06-16 12:36:47 -0600 |
---|---|---|
committer | Melody Horn / boringcactus <melody@boringcactus.com> | 2021-06-16 12:36:47 -0600 |
commit | 685b47247aad71468f190c42929ca6f0dce843fa (patch) | |
tree | 7adf64a4c00b9ca8893fab26367ec01a30e24ad9 /tests | |
parent | 92bf14bb7cc0c10f67a9a67e7512138c15db6ec0 (diff) | |
download | tosin-685b47247aad71468f190c42929ca6f0dce843fa.tar.gz tosin-685b47247aad71468f190c42929ca6f0dce843fa.zip |
make database backends generic
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tutorial/mod.rs | 54 | ||||
-rw-r--r-- | tests/tutorial_steps.rs | 7 |
2 files changed, 45 insertions, 16 deletions
diff --git a/tests/tutorial/mod.rs b/tests/tutorial/mod.rs index 71cba3d..a9eb76f 100644 --- a/tests/tutorial/mod.rs +++ b/tests/tutorial/mod.rs @@ -44,7 +44,7 @@ fn get(url: &str) -> (hyper::StatusCode, String) { .block_on(get) } -pub fn step1(dest: &str) { +pub fn step1() { // tosin-admin start-project {dest} set_current_dir(PROJECT_DIR).unwrap(); set_current_dir("target").unwrap(); @@ -52,16 +52,16 @@ pub fn step1(dest: &str) { fs::create_dir("tests").unwrap(); } set_current_dir("tests").unwrap(); - fs::write("Cargo.toml", "[workspace]\nmembers = ['tutorial1']").unwrap(); - if fs::metadata(dest).is_ok() { - fs::remove_dir_all(dest).unwrap(); + fs::write("Cargo.toml", "[workspace]\nmembers = ['tutorial']").unwrap(); + if fs::metadata("tutorial").is_ok() { + fs::remove_dir_all("tutorial").unwrap(); } Command::new(TOSIN_ADMIN) - .args(&["start-project", dest]) + .args(&["start-project", "tutorial"]) .status() .unwrap() .check(); - set_current_dir(dest).unwrap(); + set_current_dir("tutorial").unwrap(); assert!(fs::metadata("Cargo.toml").is_ok()); assert!(fs::read_to_string("Cargo.toml").unwrap().contains("tosin = ")); assert!(fs::metadata("src/main.rs").is_ok()); @@ -119,6 +119,7 @@ pub fn urls() -> UrlMap { fs::write("src/main.rs", r#" use tosin::Settings; use tosin::contrib::admin; +use tosin::db::backend::Connectable; use tosin::urls::{UrlMap, url_map}; mod polls; @@ -130,7 +131,7 @@ fn urls() -> UrlMap { } } -fn settings() -> Settings { +fn settings() -> Settings<impl Connectable> { Settings { ..Settings::default() } @@ -169,7 +170,40 @@ tosin::main!(urls(), settings()); } } -pub fn step2(dest: &str) { - step1(dest); - todo!(); +pub fn step2() { + step1(); + // update main.rs + fs::write("src/main.rs", r#" +use tosin::Settings; +use tosin::contrib::admin; +use tosin::db::backend::Connectable; +use tosin::urls::{UrlMap, url_map}; + +mod polls; + +fn urls() -> UrlMap { + url_map! { + "polls" / ..polls::urls(), + "admin" / ..admin::site::urls(), + } +} + +fn settings() -> Settings<impl Connectable> { + Settings { + installed_apps: &[ + &admin::APP, + ], + ..Settings::default() + } +} + +tosin::main!(urls(), settings()); + "#).unwrap(); + + // cargo run migrate + Command::new(CARGO) + .args(&["run", "migrate"]) + .status() + .unwrap() + .check(); } diff --git a/tests/tutorial_steps.rs b/tests/tutorial_steps.rs index 5af6eb5..63c05e8 100644 --- a/tests/tutorial_steps.rs +++ b/tests/tutorial_steps.rs @@ -3,11 +3,6 @@ mod tutorial; use tutorial::*; #[test] -fn tutorial1() { - step1("tutorial1"); -} - -#[test] fn tutorial2() { - step2("tutorial2"); + step2(); } |