30 lines
2.2 KiB
Plaintext
30 lines
2.2 KiB
Plaintext
use dever_runtime::{task::{self, RunError}, value::secret::Secret};
|
|
let password = Secret::from_input(b"test-only-password".to_vec());
|
|
let hash = task::run(true, 1, async |scope| @hash@(scope, password.clone()).await).unwrap().unwrap();
|
|
assert!(hash.starts_with("$argon2id$v=19$m=19456,t=2,p=1$"));
|
|
assert!(task::run(true, 1, async |scope| @verify@(scope, password.clone(), hash.clone()).await).unwrap().unwrap());
|
|
assert!(task::run(true, 1, async |scope| @spawned@(scope, password.clone(), hash.clone()).await).unwrap().unwrap());
|
|
assert_eq!(task::run(true, 1, async |scope| @multiple@(scope, password.clone(), hash.clone()).await).unwrap().unwrap(), hash.len() as i64);
|
|
assert!(task::run(true, 1, async |scope| @handled@(scope, password.clone(), hash.clone()).await).unwrap().unwrap());
|
|
assert!(task::run(true, 1, async |scope| @together@(scope, password.clone(), hash.clone()).await).unwrap().unwrap());
|
|
task::run(true, 1, async |scope| @grouped@(scope, password.clone(), hash.clone()).await).unwrap().unwrap();
|
|
assert!(!task::run(true, 1, async |scope| Ok::<_, ()>(@captured@(scope, password.clone(), "invalid".into()).await)).unwrap().unwrap());
|
|
assert!(matches!(task::run(true, 1, async |scope| @argumentFailure@(scope, password.clone(), String::new()).await).unwrap(), Err(RunError::Business { .. })));
|
|
for spawned in [false, true] {
|
|
match task::run(true, 1, async |scope| {
|
|
if spawned { @spawnedOverflow@(scope, password.clone(), hash.clone(), i64::MAX).await }
|
|
else { @overflow@(scope, password.clone(), hash.clone(), i64::MAX).await }
|
|
}).unwrap() {
|
|
Err(RunError::Fault { primary, additional }) => {
|
|
assert_eq!(primary.downcast_ref::<&'static FaultInfo>().unwrap().source, @source_path@);
|
|
assert!(additional.is_empty());
|
|
}
|
|
_ => panic!("expected original arithmetic fault"),
|
|
}
|
|
}
|
|
let path = std::path::Path::new(@source_path@).with_extension("json");
|
|
std::fs::write(&path, format!(r#"{{"module":{{"main":{{"main":{{"password":"test-only-password","saved_hash":"{hash}"}}}}}}}}"#)).unwrap();
|
|
let settings = load_settings(&path).unwrap();
|
|
assert!(task::run(true, 1, async |scope| @configured@(scope, &settings).await).unwrap().unwrap());
|
|
assert_eq!(std::sync::Arc::strong_count(&settings), 1);
|