app init test

[?]
May 20, 2025, 7:19 PM
VCNKFNUF7OWVSWC6I5D25KUZ3XZZICZ3LHWVPF2N5ZSP7LQ2JOUQC

Dependencies

Change contents

  • file addition: testing.rs (----------)
    [15.31]
    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 ID
    pub 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 key
    credentials: Some(Credentials::new(secret_key, None)),
    };
    id.write().unwrap();
    PijulId { dir, skey }
    }
    /// Setup an empty Pijul repo in a temp dir
    pub 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,
    }
  • edit in libflorescence/src/lib.rs at line 9
    [14.618]
    #[cfg(any(test, feature = "testing"))]
    pub mod testing;
  • edit in libflorescence/Cargo.toml at line 19
    [10.4369]
    [2.2583]
    testing = ["pijul-config", "tempfile"]
  • edit in libflorescence/Cargo.toml at line 66
    [8.4655]
    [8.4655]
    workspace = true
    # "testing" feature dependencies
    [dependencies.pijul-config]
    workspace = true
    optional = true
    [dependencies.tempfile]
  • edit in libflorescence/Cargo.toml at line 74
    [8.4672]
    optional = true
    [dev-dependencies]
    [dev-dependencies.pijul-config]
    workspace = true
    [dev-dependencies.tempfile]
    workspace = true
  • file addition: test.rs (----------)
    [15.364]
    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:#?}")
    }
    }
  • replacement in inflorescence/src/task.rs at line 17
    [20.321][20.321:391]()
    pub async fn await_next_result<T>(tasks: &mut Task<T>) -> Option<T> {
    [20.321]
    [20.391]
    pub async fn await_next_msg<T>(tasks: &mut Task<T>) -> Option<T> {
  • replacement in inflorescence/src/task.rs at line 139
    [20.3482][20.3482:3539]()
    let result = await_next_result(&mut task).await;
    [20.3482]
    [20.3539]
    let result = await_next_msg(&mut task).await;
  • edit in inflorescence/src/main.rs at line 6
    [16.27]
    [11.1219]
    #[cfg(test)]
    mod test;
  • replacement in inflorescence/src/main.rs at line 51
    [8.5305][17.125:162]()
    iced::daemon(init, update, view)
    [8.5305]
    [5.509]
    let repo_path = PathBuf::from("/home/tz/dev/pijul");
    iced::daemon(move || init(repo_path.clone()), update, view)
  • replacement in inflorescence/src/main.rs at line 59
    [2.2962][18.25517:25551]()
    fn init() -> (State, Task<Msg>) {
    [2.2962]
    [17.163]
    fn init(repo_path: PathBuf) -> (State, Task<Msg>) {
  • edit in inflorescence/src/main.rs at line 62
    [20.5554]
    [20.5554]
    // TODO: `include_bytes!`?
  • edit in inflorescence/src/main.rs at line 64
    [20.5578][20.5578:5613]()
    // TODO: `include_bytes!`?
  • edit in inflorescence/src/main.rs at line 66
    [17.654][4.1124:1181](),[4.1124][4.1124:1181]()
    let repo_path = PathBuf::from("/home/tz/dev/pijul");
  • edit in inflorescence/Cargo.toml at line 37
    [20.5816]
    [20.5816]
    # Internal dependencies
    [dev-dependencies.libflorescence]
    workspace = true
    features = ["testing"]
    # External dependencies
    [dev-dependencies.assert_matches]
    workspace = true
  • edit in Cargo.toml at line 21
    [2.4172]
    [3.5909]
    [workspace.dependencies.assert_matches]
    version = "1"
  • edit in Cargo.toml at line 54
    [6.8829]
    [9.1058]
    [workspace.dependencies.pijul-config]
    path = "../pijul/pijul-config"
  • edit in Cargo.toml at line 71
    [7.7938]
    [19.9580]
    [workspace.dependencies.tempfile]
    version = "3"
  • edit in Cargo.lock at line 208
    [12.841]
    [9.1417]
    name = "assert_matches"
    version = "1.5.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
    [[package]]
  • edit in Cargo.lock at line 2724
    [13.391]
    [13.391]
    "assert_matches",
  • edit in Cargo.lock at line 2980
    [14.1122]
    [9.14473]
    "pijul-config",
  • edit in Cargo.lock at line 2987
    [14.1171]
    [3.7685]
    "tempfile",
  • replacement in Cargo.lock at line 3589
    [2.50945][18.29742:29769]()
    "proc-macro-crate 1.3.1",
    [2.50945]
    [2.50966]
    "proc-macro-crate 3.3.0",
  • replacement in Cargo.lock at line 5765
    [4.20948][18.29770:29785]()
    "rand 0.7.3",
    [4.20948]
    [4.20963]
    "rand 0.8.5",