Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/cortex-cli/src/cache_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use clap::Parser;
use serde::Serialize;
use std::path::PathBuf;

use crate::debug_cmd::utils::get_cortex_home;

/// Cache CLI command.
#[derive(Debug, Parser)]
pub struct CacheCli {
Expand Down Expand Up @@ -110,13 +112,7 @@ struct CacheCategory {

/// Get the cache directory.
fn get_cache_dir() -> PathBuf {
dirs::cache_dir()
.map(|c| c.join("cortex"))
.unwrap_or_else(|| {
dirs::home_dir()
.map(|h| h.join(".cache").join("cortex"))
.unwrap_or_else(|| PathBuf::from(".cache/cortex"))
})
get_cortex_home().join("cache")
}

/// Calculate directory size recursively.
Expand Down
31 changes: 31 additions & 0 deletions src/cortex-cli/tests/cache_paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::process::Command;

use serde_json::Value;

fn cortex_json(args: &[&str]) -> Value {
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
.args(args)
.output()
.expect("failed to run Cortex test binary");

assert!(
output.status.success(),
"Cortex {:?} failed\nstdout:\n{}\nstderr:\n{}",
args,
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);

serde_json::from_slice(&output.stdout).expect("Cortex command should print JSON")
}

#[test]
fn cache_show_json_uses_debug_paths_cache_dir() {
let cache_show = cortex_json(&["cache", "show", "--json"]);
let debug_paths = cortex_json(&["debug", "paths", "--json"]);

assert_eq!(
cache_show["cache_dir"].as_str(),
debug_paths["cache_dir"]["path"].as_str()
);
}