#![allow(clippy::unwrap_used, clippy::expect_used)]
use assert_cmd::Command;
use std::path::{Path, PathBuf};
fn examples_dir() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../examples")
}
fn collect(dir: &Path, out: &mut Vec<PathBuf>) {
for entry in std::fs::read_dir(dir).expect("examples dir is readable") {
let path = entry.expect("readable dir entry").path();
if path.is_dir() {
collect(&path, out);
} else if path
.file_name()
.is_some_and(|n| n.to_string_lossy().ends_with(".rite.yaml"))
{
out.push(path);
}
}
}
fn needs_missing_feature(path: &Path) -> bool {
!cfg!(feature = "yubikey") && path.starts_with(examples_dir().join("piv"))
}
fn ceremonies() -> Vec<PathBuf> {
let mut out = Vec::new();
collect(&examples_dir(), &mut out);
out.retain(|p| !needs_missing_feature(p));
out.sort();
assert!(
!out.is_empty(),
"no example ceremonies found under {}",
examples_dir().display()
);
out
}
#[test]
fn examples_pass_check() {
for file in ceremonies() {
Command::cargo_bin("rite")
.expect("rite binary builds")
.arg("check")
.arg(&file)
.assert()
.success();
}
}
#[test]
fn examples_complete_dry_run() {
let out_root = tempfile::tempdir().expect("create output tempdir");
for file in ceremonies() {
Command::cargo_bin("rite")
.expect("rite binary builds")
.args(["run", "--dry-run", "--no-prompt"])
.arg("-o")
.arg(out_root.path())
.arg(&file)
.assert()
.success();
}
}