@@ -408,6 +408,122 @@ async fn upload_and_get_data_with_prefix() -> Result<(), Error> {
408408 Ok ( ( ) )
409409}
410410
411+ #[ nativelink_test]
412+ async fn test_has_with_prefix ( ) -> Result < ( ) , Error > {
413+ let prefix = "has_pfx:" ;
414+
415+ let digest = DigestInfo :: try_new ( VALID_HASH1 , 2 ) ?;
416+ let packed_hash_hex = format ! ( "{prefix}{digest}" ) ;
417+
418+ let real_key = RedisValue :: Bytes ( packed_hash_hex. into ( ) ) ;
419+
420+ let mocks = Arc :: new ( MockRedisBackend :: new ( ) ) ;
421+
422+ mocks
423+ . expect (
424+ MockCommand {
425+ cmd : Str :: from_static ( "STRLEN" ) ,
426+ subcommand : None ,
427+ args : vec ! [ real_key. clone( ) ] ,
428+ } ,
429+ Ok ( RedisValue :: Integer ( 2 ) ) ,
430+ )
431+ . expect (
432+ MockCommand {
433+ cmd : Str :: from_static ( "EXISTS" ) ,
434+ subcommand : None ,
435+ args : vec ! [ real_key] ,
436+ } ,
437+ Ok ( RedisValue :: Integer ( 1 ) ) ,
438+ ) ;
439+
440+ let store = {
441+ let mut builder = Builder :: default_centralized ( ) ;
442+ builder. set_config ( RedisConfig {
443+ mocks : Some ( mocks) ,
444+ ..Default :: default ( )
445+ } ) ;
446+ let ( client_pool, subscriber_client) = make_clients ( builder) ;
447+
448+ RedisStore :: new_from_builder_and_parts (
449+ client_pool,
450+ subscriber_client,
451+ None ,
452+ mock_uuid_generator,
453+ prefix. to_string ( ) ,
454+ DEFAULT_READ_CHUNK_SIZE ,
455+ DEFAULT_MAX_CHUNK_UPLOADS_PER_UPDATE ,
456+ DEFAULT_SCAN_COUNT ,
457+ )
458+ . unwrap ( )
459+ } ;
460+
461+ let result = store. has ( digest) . await . unwrap ( ) ;
462+ assert ! (
463+ result. is_some( ) ,
464+ "Expected has() to return Some when mock indicates existence"
465+ ) ;
466+
467+ Ok ( ( ) )
468+ }
469+
470+ #[ nativelink_test]
471+ async fn test_has_without_prefix ( ) -> Result < ( ) , Error > {
472+ let digest = DigestInfo :: try_new ( VALID_HASH1 , 2 ) ?;
473+
474+ let packed_hash_hex = format ! ( "{digest}" ) ;
475+ let real_key = RedisValue :: Bytes ( packed_hash_hex. into ( ) ) ;
476+
477+ let mocks = Arc :: new ( MockRedisBackend :: new ( ) ) ;
478+
479+ mocks
480+ . expect (
481+ MockCommand {
482+ cmd : Str :: from_static ( "STRLEN" ) ,
483+ subcommand : None ,
484+ args : vec ! [ real_key. clone( ) ] ,
485+ } ,
486+ Ok ( RedisValue :: Integer ( 2 ) ) ,
487+ )
488+ . expect (
489+ MockCommand {
490+ cmd : Str :: from_static ( "EXISTS" ) ,
491+ subcommand : None ,
492+ args : vec ! [ real_key] ,
493+ } ,
494+ Ok ( RedisValue :: Integer ( 1 ) ) ,
495+ ) ;
496+
497+ let store = {
498+ let mut builder = Builder :: default_centralized ( ) ;
499+ builder. set_config ( RedisConfig {
500+ mocks : Some ( mocks) ,
501+ ..Default :: default ( )
502+ } ) ;
503+ let ( client_pool, subscriber_client) = make_clients ( builder) ;
504+
505+ RedisStore :: new_from_builder_and_parts (
506+ client_pool,
507+ subscriber_client,
508+ None ,
509+ mock_uuid_generator,
510+ String :: new ( ) ,
511+ DEFAULT_READ_CHUNK_SIZE ,
512+ DEFAULT_MAX_CHUNK_UPLOADS_PER_UPDATE ,
513+ DEFAULT_SCAN_COUNT ,
514+ )
515+ . unwrap ( )
516+ } ;
517+
518+ let result = store. has ( digest) . await . unwrap ( ) ;
519+ assert ! (
520+ result. is_some( ) ,
521+ "Expected has() to return Some when mock indicates existence (no prefix)"
522+ ) ;
523+
524+ Ok ( ( ) )
525+ }
526+
411527#[ nativelink_test]
412528async fn upload_empty_data ( ) -> Result < ( ) , Error > {
413529 let data = Bytes :: from_static ( b"" ) ;
0 commit comments