@@ -248,6 +248,10 @@ pub enum CliCommand {
248248 /// Required cached-object storage tier. May be repeated: memory, disk.
249249 #[ arg( long = "expect-tier" , value_name = "TIER" ) ]
250250 expect_tiers : Vec < String > ,
251+
252+ /// Require at least one matching cached object to be present in the purge index.
253+ #[ arg( long) ]
254+ expect_purge_indexed : bool ,
251255 } ,
252256}
253257
@@ -477,6 +481,7 @@ fn run_command(
477481 expect_freshness_states,
478482 expect_statuses,
479483 expect_tiers,
484+ expect_purge_indexed,
480485 } => run_cache_lookup_command ( CacheLookupOptions {
481486 config_path,
482487 host : host. clone ( ) ,
@@ -488,6 +493,7 @@ fn run_command(
488493 expect_freshness_states : expect_freshness_states. clone ( ) ,
489494 expect_statuses : expect_statuses. clone ( ) ,
490495 expect_tiers : expect_tiers. clone ( ) ,
496+ expect_purge_indexed : * expect_purge_indexed,
491497 } ) ,
492498 }
493499}
@@ -533,6 +539,7 @@ struct CacheLookupOptions<'a> {
533539 expect_freshness_states : Vec < String > ,
534540 expect_statuses : Vec < u16 > ,
535541 expect_tiers : Vec < String > ,
542+ expect_purge_indexed : bool ,
536543}
537544
538545#[ cfg( feature = "cache" ) ]
@@ -870,6 +877,7 @@ fn run_cache_lookup_command(
870877 & expected_states,
871878 & options. expect_statuses ,
872879 & expected_tiers,
880+ options. expect_purge_indexed ,
873881 ) ?;
874882
875883 println ! ( "cache object lookup:" ) ;
@@ -973,6 +981,7 @@ fn validate_cache_lookup_expectations(
973981 expected_states : & [ crate :: cache:: CacheObjectFreshnessState ] ,
974982 expected_statuses : & [ u16 ] ,
975983 expected_tiers : & [ crate :: cache:: CacheObjectTier ] ,
984+ expect_purge_indexed : bool ,
976985) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
977986 if require_object && lookup. objects . is_empty ( ) {
978987 return Err ( "cache-lookup expected at least one cached object, found none" . into ( ) ) ;
@@ -1051,6 +1060,9 @@ fn validate_cache_lookup_expectations(
10511060 return Err ( format ! ( "cache-lookup expected tier {expected}, found {found}" ) . into ( ) ) ;
10521061 }
10531062 }
1063+ if expect_purge_indexed && !lookup. objects . iter ( ) . any ( |object| object. purge_indexed ) {
1064+ return Err ( "cache-lookup expected at least one purge-indexed object, found none" . into ( ) ) ;
1065+ }
10541066 Ok ( ( ) )
10551067}
10561068
@@ -1098,13 +1110,15 @@ fn run_cache_lookup_command(
10981110 expect_freshness_states,
10991111 expect_statuses,
11001112 expect_tiers,
1113+ expect_purge_indexed,
11011114 } = options;
11021115 let _ = ( config_path, host, headers, method, path, query) ;
11031116 let _ = (
11041117 require_object,
11051118 expect_freshness_states,
11061119 expect_statuses,
11071120 expect_tiers,
1121+ expect_purge_indexed,
11081122 ) ;
11091123 Err ( "cache-lookup requires the proxy and cache features" . into ( ) )
11101124}
@@ -2785,7 +2799,7 @@ mod tests {
27852799 let tiers = super :: parse_cache_lookup_tiers ( & [ "memory" . to_owned ( ) ] ) . unwrap ( ) ;
27862800
27872801 assert ! (
2788- super :: validate_cache_lookup_expectations( & lookup, true , & states, & [ 200 ] , & tiers)
2802+ super :: validate_cache_lookup_expectations( & lookup, true , & states, & [ 200 ] , & tiers, true )
27892803 . is_ok( )
27902804 ) ;
27912805 assert ! (
@@ -2794,14 +2808,15 @@ mod tests {
27942808 false ,
27952809 & [ crate :: cache:: CacheObjectFreshnessState :: Fresh ] ,
27962810 & [ ] ,
2797- & [ ]
2811+ & [ ] ,
2812+ false
27982813 )
27992814 . unwrap_err( )
28002815 . to_string( )
28012816 . contains( "expected freshness state fresh, found stale" )
28022817 ) ;
28032818 assert ! (
2804- super :: validate_cache_lookup_expectations( & lookup, false , & [ ] , & [ 404 ] , & [ ] )
2819+ super :: validate_cache_lookup_expectations( & lookup, false , & [ ] , & [ 404 ] , & [ ] , false )
28052820 . unwrap_err( )
28062821 . to_string( )
28072822 . contains( "expected status 404, found 200" )
@@ -2812,7 +2827,8 @@ mod tests {
28122827 false ,
28132828 & [ ] ,
28142829 & [ ] ,
2815- & [ crate :: cache:: CacheObjectTier :: Disk ]
2830+ & [ crate :: cache:: CacheObjectTier :: Disk ] ,
2831+ false
28162832 )
28172833 . unwrap_err( )
28182834 . to_string( )
@@ -2837,12 +2853,26 @@ mod tests {
28372853 true ,
28382854 & [ ] ,
28392855 & [ ] ,
2840- & [ ]
2856+ & [ ] ,
2857+ false
28412858 )
28422859 . unwrap_err( )
28432860 . to_string( )
28442861 . contains( "expected at least one cached object" )
28452862 ) ;
2863+ assert ! (
2864+ super :: validate_cache_lookup_expectations(
2865+ & cache_lookup_without_objects( ) ,
2866+ false ,
2867+ & [ ] ,
2868+ & [ ] ,
2869+ & [ ] ,
2870+ true
2871+ )
2872+ . unwrap_err( )
2873+ . to_string( )
2874+ . contains( "expected at least one purge-indexed object" )
2875+ ) ;
28462876 }
28472877
28482878 #[ cfg( all( feature = "cache" , feature = "proxy" ) ) ]
0 commit comments