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RTFN3NC4WGJQC use chrono::Utc;use derivative::Derivative;use libpijul::key::SKey;use pijul_identity::Credentials;use pijul_repository::Repository;use tempfile::{tempdir, TempDir};/// Setup a Pijul ID in a temp dir. Sets `PIJUL_CONFIG_DIR` env var, which is/// used by pijul when loading IDpub fn setup_pijul_id() -> PijulId {let dir = tempdir().unwrap();unsafe { std::env::set_var("PIJUL_CONFIG_DIR", &dir.path().as_os_str()) };let skey = SKey::generate(None);let secret_key = skey.save(None);let public_key = skey.public_key();let id = pijul_identity::Complete {name: "Fandan".to_string(),config: pijul_identity::Config {author: pijul_config::Author {username: "fandan".to_string(),display_name: "Fan Dan".to_string(),email: "fan@dan.com".to_string(),origin: "ssh.pijul.com".to_string(),key_path: None,},key_path: None,},last_modified: Utc::now(),public_key,// TODO what happens when this is None? Currently `identity::load` fails// as it needs to be able to read the keycredentials: Some(Credentials::new(secret_key, None)),};id.write().unwrap();PijulId { dir, skey }}/// Setup an empty Pijul repo in a temp dirpub fn setup_pijul_repo() -> PijulRepo {let dir = tempdir().unwrap();let repo =Repository::init(Some(dir.path().to_path_buf()), None, None).unwrap();let mut txn = repo.pristine.mut_txn_begin().unwrap();let channel_name = libpijul::DEFAULT_CHANNEL.to_string();libpijul::MutTxnT::open_or_create_channel(&mut txn, &channel_name).unwrap();libpijul::MutTxnT::set_current_channel(&mut txn, &channel_name).unwrap();libpijul::MutTxnT::commit(txn).unwrap();PijulRepo { dir }}#[derive(Derivative)]#[derivative(Debug)]pub struct PijulId {pub dir: TempDir,#[derivative(Debug = "ignore")]pub skey: SKey,}#[derive(Debug)]pub struct PijulRepo {pub dir: TempDir,}
#[cfg(any(test, feature = "testing"))]pub mod testing;
optional = true[dev-dependencies][dev-dependencies.pijul-config]workspace = true[dev-dependencies.tempfile]workspace = true
use crate::{init, task, Msg};use libflorescence::repo;use libflorescence::testing::{setup_pijul_id, setup_pijul_repo};#[tokio::test]async fn test_init() {let _id = setup_pijul_id();let repo = setup_pijul_repo();let repo_path = repo.dir.path();let (state, mut tasks) = init(repo_path.to_path_buf());assert_eq!(state.repo_path, repo_path);// Must receive 3 messages:// - Msg::WindowOpened// - Msg::LoadedId// - Msg::FromRepo(repo::MsgOut::Init)let msg_0 = task::await_next_msg(&mut tasks).await.unwrap();let msg_1 = task::await_next_msg(&mut tasks).await.unwrap();let msg_2 = task::await_next_msg(&mut tasks).await.unwrap();let mut window_opened = false;let mut loaded_id = false;let mut inited_repo = false;for msg in [msg_0, msg_1, msg_2] {if !window_opened && matches!(msg, Msg::WindowOpened(_)) {window_opened = true;continue;}if !loaded_id && matches!(msg, Msg::LoadedId(_)) {loaded_id = true;continue;}if !inited_repo && matches!(msg, Msg::FromRepo(repo::MsgOut::Init(_))) {inited_repo = true;continue;}}let all = [window_opened, loaded_id, inited_repo];if !all.iter().all(|success| *success) {panic!("Some task didn't complete {all:#?}")}}