@@ -3,7 +3,7 @@ mod tests {
3
3
use serde:: { Deserialize , Serialize } ;
4
4
use simd_r_drive:: DataStore ;
5
5
use simd_r_drive_extensions:: {
6
- utils :: prefix_key , StorageOptionExt , TEST_OPTION_PREFIX , TEST_OPTION_TOMBSTONE_MARKER ,
6
+ NamespaceHasher , StorageOptionExt , TEST_OPTION_PREFIX , TEST_OPTION_TOMBSTONE_MARKER ,
7
7
} ;
8
8
use std:: io:: ErrorKind ;
9
9
use tempfile:: tempdir;
@@ -106,8 +106,11 @@ mod tests {
106
106
"Entry should return None when tombstone is written"
107
107
) ;
108
108
109
+ let namespace_hasher = NamespaceHasher :: new ( TEST_OPTION_PREFIX ) ;
110
+ let namespaced_key = namespace_hasher. namespace ( key) ;
111
+
109
112
// Step 4: Ensure the entry still exists in storage (not fully deleted)
110
- let raw_entry = storage. read ( & prefix_key ( & TEST_OPTION_PREFIX , key ) ) ;
113
+ let raw_entry = storage. read ( & namespaced_key ) ;
111
114
assert ! (
112
115
raw_entry. is_some( ) ,
113
116
"Entry should still exist in storage even after writing None"
@@ -219,8 +222,10 @@ mod tests {
219
222
fn test_option_prefix_is_applied_for_some ( ) {
220
223
let ( _dir, storage) = create_temp_storage ( ) ;
221
224
225
+ let namespace_hasher = NamespaceHasher :: new ( TEST_OPTION_PREFIX ) ;
226
+
222
227
let key = b"test_key_option" ;
223
- let prefixed_key = prefix_key ( TEST_OPTION_PREFIX , key) ;
228
+ let namespaced_key = namespace_hasher . namespace ( key) ;
224
229
let test_value = Some ( TestData {
225
230
id : 456 ,
226
231
name : "Test Option Value" . to_string ( ) ,
@@ -232,7 +237,7 @@ mod tests {
232
237
. expect ( "Failed to write option" ) ;
233
238
234
239
// Ensure the prefixed key exists in storage
235
- let raw_data = storage. read ( & prefixed_key ) ;
240
+ let raw_data = storage. read ( & namespaced_key ) ;
236
241
assert ! (
237
242
raw_data. is_some( ) ,
238
243
"Expected data to be stored under the prefixed key"
@@ -260,16 +265,18 @@ mod tests {
260
265
fn test_option_prefix_is_applied_for_none ( ) {
261
266
let ( _dir, storage) = create_temp_storage ( ) ;
262
267
268
+ let namespace_hasher = NamespaceHasher :: new ( TEST_OPTION_PREFIX ) ;
269
+
263
270
let key = b"test_key_none" ;
264
- let prefixed_key = prefix_key ( TEST_OPTION_PREFIX , key) ;
271
+ let namespaced_key = namespace_hasher . namespace ( key) ;
265
272
266
273
// Write `None`
267
274
storage
268
275
. write_option :: < TestData > ( key, None )
269
276
. expect ( "Failed to write None with option handling" ) ;
270
277
271
278
// Ensure the prefixed key exists in storage (tombstone marker stored)
272
- let raw_data = storage. read ( & prefixed_key ) ;
279
+ let raw_data = storage. read ( & namespaced_key ) ;
273
280
assert ! (
274
281
raw_data. is_some( ) ,
275
282
"Expected tombstone marker to be stored under the prefixed key"
@@ -308,9 +315,11 @@ mod tests {
308
315
. write ( key, & bincode:: serialize ( & test_value) . unwrap ( ) )
309
316
. expect ( "Failed to write non-option value" ) ;
310
317
318
+ let namespace_hasher = NamespaceHasher :: new ( TEST_OPTION_PREFIX ) ;
319
+
311
320
// Ensure reading from the option-prefixed key fails (since it was not stored as an option)
312
- let prefixed_key = prefix_key ( TEST_OPTION_PREFIX , key) ;
313
- let raw_data_prefixed = storage. read ( & prefixed_key ) ;
321
+ let namespaced_key = namespace_hasher . namespace ( key) ;
322
+ let raw_data_prefixed = storage. read ( & namespaced_key ) ;
314
323
assert ! (
315
324
raw_data_prefixed. is_none( ) ,
316
325
"No option-prefixed entry should exist for a non-prefixed write"
0 commit comments