Skip to content

Commit 8e15cf4

Browse files
committed
fix: align cache command path
1 parent 7954d02 commit 8e15cf4

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

src/cortex-cli/src/cache_cmd.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use clap::Parser;
1010
use serde::Serialize;
1111
use std::path::PathBuf;
1212

13+
use crate::debug_cmd::utils::get_cortex_home;
14+
1315
/// Cache CLI command.
1416
#[derive(Debug, Parser)]
1517
pub struct CacheCli {
@@ -110,13 +112,7 @@ struct CacheCategory {
110112

111113
/// Get the cache directory.
112114
fn get_cache_dir() -> PathBuf {
113-
dirs::cache_dir()
114-
.map(|c| c.join("cortex"))
115-
.unwrap_or_else(|| {
116-
dirs::home_dir()
117-
.map(|h| h.join(".cache").join("cortex"))
118-
.unwrap_or_else(|| PathBuf::from(".cache/cortex"))
119-
})
115+
get_cortex_home().join("cache")
120116
}
121117

122118
/// Calculate directory size recursively.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::process::Command;
2+
3+
use serde_json::Value;
4+
5+
fn cortex_json(args: &[&str]) -> Value {
6+
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
7+
.args(args)
8+
.output()
9+
.expect("failed to run Cortex test binary");
10+
11+
assert!(
12+
output.status.success(),
13+
"Cortex {:?} failed\nstdout:\n{}\nstderr:\n{}",
14+
args,
15+
String::from_utf8_lossy(&output.stdout),
16+
String::from_utf8_lossy(&output.stderr)
17+
);
18+
19+
serde_json::from_slice(&output.stdout).expect("Cortex command should print JSON")
20+
}
21+
22+
#[test]
23+
fn cache_show_json_uses_debug_paths_cache_dir() {
24+
let cache_show = cortex_json(&["cache", "show", "--json"]);
25+
let debug_paths = cortex_json(&["debug", "paths", "--json"]);
26+
27+
assert_eq!(
28+
cache_show["cache_dir"].as_str(),
29+
debug_paths["cache_dir"]["path"].as_str()
30+
);
31+
}

0 commit comments

Comments
 (0)