use std::path::Path;
use std::process::{Command, Output, Stdio};
fn nib(folder: &Path, arguments: &[&str]) -> Output {
Command::new(env!("CARGO_BIN_EXE_nib"))
.arg("--library")
.arg(folder.join("library"))
.args(arguments)
.env("NIBKEEP_NO_KEYSTORE", "1")
.env("NIBKEEP_PASSPHRASE_FILE", folder.join("passphrase"))
.env(
"DBUS_SESSION_BUS_ADDRESS",
"unix:path=/nonexistent/nibkeep-no-bus",
)
.stdin(Stdio::null())
.output()
.expect("runs")
}
#[test]
fn nib_finds_no_keystore_where_tests_say_so() {
if std::env::var_os("NIBKEEP_TEST_DIR").is_some() {
eprintln!("skipped: the program is not on this device");
return;
}
if !cfg!(target_os = "linux") && std::env::var_os("CI").is_none() {
eprintln!("skipped: outside CI, a failing switch would reach this computer's keystore");
return;
}
let folder = nibkeep_testkit::empty_directory(env!("CARGO_TARGET_TMPDIR"), "no keystore");
std::fs::create_dir(folder.join("library")).expect("makes the library's folder");
nibkeep_testkit::write_private(&folder.join("passphrase"), "correct horse\n");
let started = nib(&folder, &["init", "--name", "Ada", "--languages", "en"]);
assert!(started.status.success(), "{started:?}");
let protected = nib(&folder, &["protect"]);
assert_eq!(protected.status.code(), Some(1), "{protected:?}");
assert_eq!(
String::from_utf8_lossy(&protected.stderr),
"nib: there is no platform keystore here; nib protect --passphrase protects with a passphrase\n"
);
}