mod fixtures;
use btctax_cli::{cmd, Session};
use btctax_store::Passphrase;
fn pp() -> Passphrase {
Passphrase::new("pw".into())
}
#[test]
fn open_missing_vault_names_path_and_hint() {
let dir = tempfile::tempdir().unwrap();
let vault = dir.path().join("does_not_exist.pgp");
let err = Session::open(&vault, &pp()).expect_err("a missing vault must error");
let msg = err.to_string();
assert!(
msg.contains(&vault.display().to_string()),
"names the vault path: {msg}"
);
assert!(msg.contains("--vault"), "hints the --vault flag: {msg}");
assert!(msg.contains("init"), "hints `btctax init`: {msg}");
assert!(
!msg.contains("No such file or directory (os error 2)")
|| msg.contains(&vault.display().to_string()),
"the raw errno may remain as the source, but the path must be present: {msg}"
);
}
#[test]
fn export_out_collision_names_path() {
let dir = tempfile::tempdir().unwrap();
let vault = dir.path().join("vault.pgp");
cmd::init::run(&vault, &pp(), &dir.path().join("k.asc")).unwrap();
cmd::import::run(
&vault,
&pp(),
&[fixtures::coinbase_buy_sell_send(dir.path())],
)
.unwrap();
let out = dir.path().join("collide");
std::fs::write(&out, b"i am a file, not a directory").unwrap();
let err = cmd::admin::export_snapshot(&vault, &pp(), &out, None, None)
.expect_err("an --out that collides with a file must error");
let msg = err.to_string();
assert!(
msg.contains(&out.display().to_string()),
"names the --out path: {msg}"
);
assert!(
msg.contains("does not already exist as a file"),
"carries the export-out hint (fold M2): {msg}"
);
}
#[test]
fn export_out_subpath_collision_names_path() {
let dir = tempfile::tempdir().unwrap();
let vault = dir.path().join("vault.pgp");
cmd::init::run(&vault, &pp(), &dir.path().join("k.asc")).unwrap();
cmd::import::run(
&vault,
&pp(),
&[fixtures::coinbase_buy_sell_send(dir.path())],
)
.unwrap();
let out = dir.path().join("export");
std::fs::create_dir(&out).unwrap();
std::fs::create_dir(out.join("lots.csv")).unwrap();
let err = cmd::admin::export_snapshot(&vault, &pp(), &out, None, None)
.expect_err("a lots.csv-as-directory subpath collision must error");
let msg = err.to_string();
assert!(
msg.contains(&out.display().to_string()),
"names the --out path even for a Store(Io) subpath failure: {msg}"
);
assert!(
msg.contains("does not already exist"),
"carries the export-out hint: {msg}"
);
}
#[test]
fn backup_key_out_collision_names_path() {
let dir = tempfile::tempdir().unwrap();
let vault = dir.path().join("vault.pgp");
cmd::init::run(&vault, &pp(), &dir.path().join("k.asc")).unwrap();
let out = dir.path().join("outdir");
std::fs::create_dir(&out).unwrap();
let err = cmd::admin::backup_key(&vault, &pp(), &out)
.expect_err("writing a key onto an existing directory must error");
let msg = err.to_string();
assert!(
msg.contains(&out.display().to_string()),
"names the --out path: {msg}"
);
}