Ensuring that tests won't step on real key files
This commit is contained in:
@@ -8,11 +8,10 @@ use pem::Pem;
|
|||||||
|
|
||||||
use bft_json_crdt::keypair::{make_keypair, KeyPair};
|
use bft_json_crdt::keypair::{make_keypair, KeyPair};
|
||||||
|
|
||||||
const KEY_FILE: &str = ".side/node/keys.pem";
|
const KEY_FILE: &str = "side/node/keys.pem";
|
||||||
|
|
||||||
pub(crate) fn init() -> Result<(), std::io::Error> {
|
pub(crate) fn init(home: String) -> Result<(), std::io::Error> {
|
||||||
println!("Initializing Side Node");
|
println!("Initializing Side Node at {home}");
|
||||||
let home = std::env::var("HOME").expect("couldn't read home directory env variable");
|
|
||||||
let key_path = key_path(home);
|
let key_path = key_path(home);
|
||||||
|
|
||||||
ensure_directory_exists(&key_path)?;
|
ensure_directory_exists(&key_path)?;
|
||||||
@@ -59,15 +58,18 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn creates_side_node_directory() {
|
fn creates_side_node_directory() {
|
||||||
let node_dir = Path::new(KEY_FILE).parent().unwrap().to_str().unwrap();
|
let test_home = format!("/tmp/{KEY_FILE}");
|
||||||
let _ = init();
|
let node_dir = Path::new(&test_home).parent().unwrap().to_str().unwrap();
|
||||||
|
let _ = init(test_home.clone());
|
||||||
assert!(std::path::Path::new(node_dir).exists());
|
assert!(std::path::Path::new(node_dir).exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn creates_key_file() {
|
fn creates_key_file() {
|
||||||
let _ = init();
|
let test_home = format!("/tmp/{KEY_FILE}");
|
||||||
assert!(std::path::Path::new(KEY_FILE).exists());
|
let node_dir = Path::new(&test_home).parent().unwrap().to_str().unwrap();
|
||||||
|
let _ = init(test_home.clone());
|
||||||
|
assert!(std::path::Path::new(node_dir).exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ async fn main() {
|
|||||||
|
|
||||||
match &args.command {
|
match &args.command {
|
||||||
Some(Commands::Init {}) => {
|
Some(Commands::Init {}) => {
|
||||||
let _ = init::init();
|
let home = std::env::var("HOME").expect("couldn't read home directory env variable");
|
||||||
|
let _ = init::init(home);
|
||||||
}
|
}
|
||||||
Some(Commands::Run {}) => {
|
Some(Commands::Run {}) => {
|
||||||
let (mut bft_crdt, keys) = list_transaction_crdt::new();
|
let (mut bft_crdt, keys) = list_transaction_crdt::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user