Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ mod tests {
use super::*;
use std::fs;
use std::path::Path;
use std::sync::atomic::{AtomicU64, Ordering};

fn parse(args: &[&str]) -> Result<Invocation, String> {
CliArgs::parse(args.iter().map(|s| s.to_string()))
Expand Down Expand Up @@ -609,14 +610,20 @@ mod tests {

// --- Config file integration tests -------------------------------------

static NEXT_TEMP_CONF_ID: AtomicU64 = AtomicU64::new(0);

struct TempConf {
path: PathBuf,
}

impl TempConf {
fn new(name: &str, body: &str) -> Self {
let mut dir = std::env::temp_dir();
dir.push(format!("ferrum-cli-{name}-{}.conf", std::process::id()));
let id = NEXT_TEMP_CONF_ID.fetch_add(1, Ordering::Relaxed);
dir.push(format!(
"ferrum-cli-{name}-{}-{id}.conf",
std::process::id()
));
fs::write(&dir, body).expect("write temp conf");
Self { path: dir }
}
Expand All @@ -628,6 +635,16 @@ mod tests {
}
}

#[test]
fn temp_conf_paths_are_unique_for_reused_names() {
let first = TempConf::new("reused", "port 7000\n");
let second = TempConf::new("reused", "port 7001\n");

assert_ne!(first.path, second.path);
assert_eq!(fs::read_to_string(&first.path).unwrap(), "port 7000\n");
assert_eq!(fs::read_to_string(&second.path).unwrap(), "port 7001\n");
}

#[test]
fn config_file_supplies_addr_from_bind_and_port() {
let conf = TempConf::new("bind-port", "bind 0.0.0.0\nport 7000\n");
Expand Down
Loading