mod common; use assert_cmd::Command; use predicates::str::contains; #[test] fn completions_bash_emits_script() { Command::cargo_bin("relicario").unwrap() .args(["completions", "bash"]) .assert() .success() .stdout(contains("_relicario")) .stdout(contains("complete -F")); } #[test] fn completions_zsh_emits_script() { Command::cargo_bin("relicario").unwrap() .args(["completions", "zsh"]) .assert() .success() .stdout(contains("#compdef relicario")); } #[test] fn completions_fish_emits_script() { Command::cargo_bin("relicario").unwrap() .args(["completions", "fish"]) .assert() .success() .stdout(contains("complete -c relicario")); } #[test] fn list_command_refreshes_groups_cache() { let v = common::TestVault::init(); let out = v.run(&[ "add", "login", "--title", "T", "--username", "u", "--group", "work", "--password", "hunter2", ]); assert!(out.status.success(), "add failed: {:?}", out); let out = v.run(&["list"]); assert!(out.status.success(), "list failed: {:?}", out); let cache_path = v.path().join(".relicario/groups.cache"); let cache = std::fs::read_to_string(&cache_path) .unwrap_or_else(|e| panic!("groups.cache not found at {}: {e}", cache_path.display())); assert!( cache.lines().any(|l| l == "work"), "expected 'work' in groups.cache, got: {cache:?}" ); } #[test] fn no_groups_cache_env_var_suppresses_write() { use std::process::{Command as StdCommand, Stdio}; use assert_cmd::cargo::CommandCargoExt as _; let v = common::TestVault::init(); // Add with the env var set so no cache is created by add either. let out = StdCommand::cargo_bin("relicario").unwrap() .current_dir(v.path()) .env("RELICARIO_IMAGE", &v.reference_image) .env("RELICARIO_TEST_PASSPHRASE", &v.passphrase) .env("RELICARIO_NO_GROUPS_CACHE", "1") .args([ "add", "login", "--title", "T2", "--username", "u", "--group", "personal", "--password", "hunter2", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .unwrap(); assert!(out.status.success(), "add failed: {:?}", out); // Run list with RELICARIO_NO_GROUPS_CACHE=1 — cache must NOT be written. let out = StdCommand::cargo_bin("relicario").unwrap() .current_dir(v.path()) .env("RELICARIO_IMAGE", &v.reference_image) .env("RELICARIO_TEST_PASSPHRASE", &v.passphrase) .env("RELICARIO_NO_GROUPS_CACHE", "1") .args(["list"]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .unwrap(); assert!(out.status.success(), "list failed: {:?}", out); let cache_path = v.path().join(".relicario/groups.cache"); assert!( !cache_path.exists(), "groups.cache should not exist when RELICARIO_NO_GROUPS_CACHE=1" ); }