#![cfg(all(feature = "on-disk-cache", not(windows)))]
use assert_cmd::cargo::cargo_bin_cmd;
use std::path::Path;
use tempfile::tempdir;
const TEST_PACKAGE: &str = "anyhow";
const CACHE_VERSION: &str = "v2";
#[allow(clippy::disallowed_methods)]
#[test]
fn test_no_cache() {
let cache_dir = tempdir().unwrap();
let cache_root_path = cache_dir.path().join("cargo-unmaintained");
let cache_version_path = cache_root_path.join(CACHE_VERSION);
let entries_path = cache_version_path.join("entries");
let package_entry_path = entries_path.join(TEST_PACKAGE);
let run_command = |args: &[&str]| {
let mut cmd = cargo_bin_cmd!("cargo-unmaintained");
cmd.arg("unmaintained");
cmd.args(args);
cmd.env("XDG_CACHE_HOME", cache_dir.path());
cmd.arg(format!("--package={TEST_PACKAGE}"));
cmd.arg("--json");
cmd.output().unwrap();
};
let entry_exists = || Path::new(&package_entry_path).exists();
assert!(!entry_exists(), "Cache entry should not exist initially");
run_command(&[]);
assert!(entry_exists(), "Cache entry should exist after initial run");
run_command(&["--no-cache"]);
assert!(
entry_exists(),
"Cache entry should still exist after --no-cache run"
);
run_command(&["--purge"]);
assert!(!entry_exists(), "Cache entry should not exist after purge");
assert!(
!cache_root_path.exists(),
"Cache directory should not exist after purge"
);
run_command(&[]);
assert!(entry_exists(), "Cache entry should exist after final run");
}