aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2021-05-13 00:16:50 +0800
committerKunoiSayami <[email protected]>2021-05-13 00:16:50 +0800
commitb2dc72d369bbaec63e823fb8e0de698f1ce3fe3a (patch)
tree05a19e416f3e826f743c5ac7f6f3a35d2cd5a2ec
parente027dbcff8f844beb6b90b8d934e97e2a8b9bd9a (diff)
refactor(test): Use spawn process instead of call function
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs33
3 files changed, 17 insertions, 20 deletions
diff --git a/Cargo.lock b/Cargo.lock
index df05314..04ceed8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -377,7 +377,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cgit-simple-authentication"
-version = "0.3.2"
+version = "0.3.3"
dependencies = [
"anyhow",
"argon2",
diff --git a/Cargo.toml b/Cargo.toml
index 30b5a61..9457c02 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "cgit-simple-authentication"
-version = "0.3.2"
+version = "0.3.3"
authors = ["KunoiSayami <[email protected]>"]
edition = "2018"
diff --git a/src/main.rs b/src/main.rs
index 13097bc..217cffa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -595,6 +595,7 @@ mod test {
use std::time::Duration;
use std::thread::sleep;
use std::path::Path;
+ const DEFAULT_ADD_USER_ARGS: &[&str] = &["adduser", "hunter2", "hunter2", "--test"];
fn check_if_test_sqlite_only() -> bool {
std::env::var("TEST_SQLITE").is_ok()
@@ -714,12 +715,13 @@ mod test {
std::fs::remove_dir_all(tmp_dir).unwrap();
}
std::fs::create_dir(tmp_dir).unwrap();
- tokio::runtime::Builder::new_current_thread()
- .enable_all()
- .build()
+ let s = std::process::Command::new(std::env::current_exe().unwrap())
+ .arg("init --test")
+ .spawn()
.unwrap()
- .block_on(cmd_init(Config::generate_test_config()))
- .unwrap();
+ .wait()
+ .unwrap()
+ .success();
}
@@ -743,19 +745,14 @@ mod test {
}
lock(&PathBuf::from("test/tmp.db"), 3);
std::thread::sleep(std::time::Duration::from_secs(1));
- let matches = crate::get_arg_matches(Some(vec!["a", "adduser", "hunter2", "hunter2"]));
- match matches.subcommand() {
- ("adduser", Some(matches)) => {
- tokio::runtime::Builder::new_current_thread()
- .enable_all()
- .build()
- .unwrap()
- .block_on(cmd_add_user(matches, Config::generate_test_config()))
- .unwrap();
- std::fs::File::create("test/USER_WRITTEN").unwrap();
- }
- _ => {}
- }
+ let s = std::process::Command::new(std::env::current_exe().unwrap())
+ .args(DEFAULT_ADD_USER_ARGS)
+ .spawn()
+ .unwrap()
+ .wait()
+ .unwrap()
+ .success();
+ assert!(s);
}
#[test]