mod common;
use common::TempRepo;
use gitwell::git::Repo;
use gitwell::scanner::dormant::DormantScanner;
use gitwell::scanner::{Finding, Scanner};
const SIX_MONTHS: u64 = 6 * 30 * 86_400;
fn scanner() -> DormantScanner {
DormantScanner {
dormant_secs: SIX_MONTHS,
}
}
#[test]
fn repo_with_only_old_commits_is_dormant() {
let tr = TempRepo::new("dormant-old");
tr.empty_commit_at("ancient commit", 1_577_836_800);
let repo = Repo::open(tr.path()).expect("open repo");
let findings = scanner().scan(&repo);
assert_eq!(findings.len(), 1, "expected one dormant finding; got {:?}", findings);
assert!(
matches!(findings[0], Finding::DormantRepo { .. }),
"expected Finding::DormantRepo; got {:?}",
findings[0]
);
}
#[test]
fn repo_with_recent_commit_is_not_dormant() {
let tr = TempRepo::new("dormant-fresh");
let repo = Repo::open(tr.path()).expect("open repo");
let findings = scanner().scan(&repo);
assert!(
findings.is_empty(),
"a repo with a recent commit must not be dormant; got {:?}",
findings
);
}
#[test]
fn dormant_threshold_respects_config() {
let tr = TempRepo::new("dormant-threshold");
tr.empty_commit_at("ancient commit", 1_577_836_800);
let repo = Repo::open(tr.path()).expect("open repo");
let far_future = DormantScanner {
dormant_secs: 100 * 365 * 86_400,
};
let findings = far_future.scan(&repo);
assert!(
findings.is_empty(),
"100y threshold should exclude everything; got {:?}",
findings
);
}