File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ use clap::Parser;
1010use serde:: Serialize ;
1111use std:: path:: PathBuf ;
1212
13+ use crate :: debug_cmd:: utils:: get_cortex_home;
14+
1315/// Cache CLI command.
1416#[ derive( Debug , Parser ) ]
1517pub struct CacheCli {
@@ -110,13 +112,7 @@ struct CacheCategory {
110112
111113/// Get the cache directory.
112114fn 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.
Original file line number Diff line number Diff line change 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\n stdout:\n {}\n stderr:\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+ }
You can’t perform that action at this time.
0 commit comments