Skip to content

Commit

Permalink
✅(core): Improve coverage on cli/new_vault_directory.rs
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Nicolaie <[email protected]>
  • Loading branch information
xunleii committed Aug 8, 2024
1 parent e17fa71 commit 5aaaae2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/cli/new_vault_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,50 @@ impl Command {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::fs;

#[test]
fn test_run() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let vault_dir = temp_dir.path().join("vault");
let kvstore_dir = vault_dir.join(KVSTORE_DIRECTORY);
let access_control_dir = vault_dir.join(ACCESS_CONTROL_DIRECTORY);

assert!(!kvstore_dir.exists());
assert!(!access_control_dir.exists());

let command = Command {
vault_dir: vault_dir.clone(),
};
command.run().unwrap();

assert!(kvstore_dir.exists());
assert!(access_control_dir.exists());
}

#[test]
fn test_run_existing_directories() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let vault_dir = temp_dir.path().join("vault");
let kvstore_dir = vault_dir.join(KVSTORE_DIRECTORY);
let access_control_dir = vault_dir.join(ACCESS_CONTROL_DIRECTORY);

fs::create_dir_all(&kvstore_dir).unwrap();
fs::create_dir_all(&access_control_dir).unwrap();

assert!(kvstore_dir.exists());
assert!(access_control_dir.exists());

let command = Command {
vault_dir: vault_dir.clone(),
};
command.run().unwrap();

assert!(kvstore_dir.exists());
assert!(access_control_dir.exists());
}
}

0 comments on commit 5aaaae2

Please sign in to comment.