Skip to content

Commit 5dd4af4

Browse files
committed
test(cli/cache): cover run_cache subcommand dispatch — Path resolving the cache dir under SPLASHBOARD_HOME, List treating a missing cache dir as empty in both plain and json modes, Clear removing seeded .json/.lock entry files, and Clear with a widget_id dispatching through run_cache_clear to clear_one's no-entry diagnostic
1 parent 28f00b2 commit 5dd4af4

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

‎src/main.rs‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,64 @@ PATH = "/tmp/ignored"
15881588
super::run_cache_list(dir.path(), true).unwrap();
15891589
}
15901590

1591+
#[test]
1592+
fn run_cache_path_subcommand_resolves_dir_under_splashboard_home() {
1593+
let home = tempfile::tempdir().unwrap();
1594+
let _env = EnvGuard::set(vec![(
1595+
"SPLASHBOARD_HOME",
1596+
Some(home.path().display().to_string()),
1597+
)]);
1598+
super::run_cache(super::CacheSubcommand::Path).unwrap();
1599+
}
1600+
1601+
#[test]
1602+
fn run_cache_list_subcommand_treats_missing_cache_dir_as_empty() {
1603+
let home = tempfile::tempdir().unwrap();
1604+
let _env = EnvGuard::set(vec![(
1605+
"SPLASHBOARD_HOME",
1606+
Some(home.path().display().to_string()),
1607+
)]);
1608+
// `<SPLASHBOARD_HOME>/cache` does not exist yet — both modes must still succeed.
1609+
super::run_cache(super::CacheSubcommand::List { json: false }).unwrap();
1610+
super::run_cache(super::CacheSubcommand::List { json: true }).unwrap();
1611+
}
1612+
1613+
#[test]
1614+
fn run_cache_clear_subcommand_removes_seeded_entry_and_lock_files() {
1615+
let home = tempfile::tempdir().unwrap();
1616+
let _env = EnvGuard::set(vec![(
1617+
"SPLASHBOARD_HOME",
1618+
Some(home.path().display().to_string()),
1619+
)]);
1620+
let cache_dir = home.path().join("cache");
1621+
std::fs::create_dir_all(&cache_dir).unwrap();
1622+
std::fs::write(cache_dir.join("w.json"), r#"{}"#).unwrap();
1623+
std::fs::write(cache_dir.join("w.lock"), "").unwrap();
1624+
1625+
super::run_cache(super::CacheSubcommand::Clear {
1626+
widget_id: None,
1627+
yes: true,
1628+
json: true,
1629+
})
1630+
.unwrap();
1631+
1632+
assert!(!cache_dir.join("w.json").exists());
1633+
assert!(!cache_dir.join("w.lock").exists());
1634+
}
1635+
1636+
#[test]
1637+
fn run_cache_clear_with_widget_id_dispatches_to_clear_one() {
1638+
let home = tempfile::tempdir().unwrap();
1639+
let cache = tempfile::tempdir().unwrap();
1640+
let _env = EnvGuard::set(vec![(
1641+
"SPLASHBOARD_HOME",
1642+
Some(home.path().display().to_string()),
1643+
)]);
1644+
write_project_dashboard(home.path(), "basic_static");
1645+
// No cache files seeded — `clear_one` still succeeds with the "no entry" diagnostic.
1646+
super::run_cache_clear(cache.path(), Some("x".into()), false, false).unwrap();
1647+
}
1648+
15911649
#[test]
15921650
fn run_list_trusted_and_revoke_round_trip_store_entries() {
15931651
let dir = tempfile::tempdir().unwrap();

0 commit comments

Comments
 (0)