@@ -160,26 +160,24 @@ mod tests {
160160 use defs:: ContentType ;
161161 use uuid:: Uuid ;
162162
163- use tempfile:: tempdir;
163+ use tempfile:: { TempDir , tempdir} ;
164164
165- fn create_test_db ( ) -> ( RocksDbStorage , String ) {
165+ fn create_test_db ( ) -> ( RocksDbStorage , TempDir ) {
166166 let temp_dir = tempdir ( ) . unwrap ( ) ;
167- let temp_dir_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
168167
169- let db = RocksDbStorage :: new ( temp_dir_path . clone ( ) ) . expect ( "Failed to create RocksDB" ) ;
170- ( db, temp_dir_path )
168+ let db = RocksDbStorage :: new ( temp_dir . path ( ) ) . expect ( "Failed to create RocksDB" ) ;
169+ ( db, temp_dir )
171170 }
172171
173172 #[ test]
174173 fn test_new_rocksdb_storage ( ) {
175- let ( db, path) = create_test_db ( ) ;
176- assert_eq ! ( db. get_current_path( ) , PathBuf :: from( path. clone( ) ) ) ;
177- std:: fs:: remove_dir_all ( path) . unwrap_or_default ( ) ;
174+ let ( db, temp_dir) = create_test_db ( ) ;
175+ assert_eq ! ( db. get_current_path( ) , PathBuf :: from( temp_dir. path( ) ) ) ;
178176 }
179177
180178 #[ test]
181179 fn test_insert_and_get_vector ( ) {
182- let ( db, path ) = create_test_db ( ) ;
180+ let ( db, _temp_dir ) = create_test_db ( ) ;
183181 let id = Uuid :: new_v4 ( ) ;
184182 let vector = Some ( vec ! [ 0.1 , 0.2 , 0.3 ] ) ;
185183 let payload = Some ( Payload {
@@ -190,13 +188,11 @@ mod tests {
190188 assert ! ( db. insert_point( id, vector. clone( ) , payload) . is_ok( ) ) ;
191189 let result = db. get_vector ( id) . unwrap ( ) ;
192190 assert_eq ! ( result, vector) ;
193-
194- std:: fs:: remove_dir_all ( path) . unwrap_or_default ( ) ;
195191 }
196192
197193 #[ test]
198194 fn test_insert_and_get_payload ( ) {
199- let ( db, path ) = create_test_db ( ) ;
195+ let ( db, _temp_dir ) = create_test_db ( ) ;
200196 let id = Uuid :: new_v4 ( ) ;
201197 let payload = Some ( Payload {
202198 content_type : ContentType :: Text ,
@@ -212,13 +208,11 @@ mod tests {
212208 content : "Test" . to_string ( ) ,
213209 } ) ;
214210 assert_eq ! ( result, expected) ;
215-
216- std:: fs:: remove_dir_all ( path) . unwrap_or_default ( ) ;
217211 }
218212
219213 #[ test]
220214 fn test_contains_point ( ) {
221- let ( db, path ) = create_test_db ( ) ;
215+ let ( db, _temp_dir ) = create_test_db ( ) ;
222216 let id = Uuid :: new_v4 ( ) ;
223217 let payload = Some ( Payload {
224218 content_type : ContentType :: Text ,
@@ -231,13 +225,11 @@ mod tests {
231225 db. insert_point ( id, vector, payload) . unwrap ( ) ;
232226
233227 assert ! ( db. contains_point( id) . unwrap( ) ) ;
234-
235- std:: fs:: remove_dir_all ( path) . unwrap_or_default ( ) ;
236228 }
237229
238230 #[ test]
239231 fn test_delete_point ( ) {
240- let ( db, path ) = create_test_db ( ) ;
232+ let ( db, _temp_dir ) = create_test_db ( ) ;
241233 let id = Uuid :: new_v4 ( ) ;
242234 let payload = Some ( Payload {
243235 content_type : ContentType :: Text ,
@@ -255,27 +247,21 @@ mod tests {
255247 assert ! ( !db. contains_point( id) . unwrap( ) ) ;
256248 assert_eq ! ( db. get_vector( id) . unwrap( ) , None ) ;
257249 assert_eq ! ( db. get_payload( id) . unwrap( ) , None ) ;
258-
259- std:: fs:: remove_dir_all ( path) . unwrap_or_default ( ) ;
260250 }
261251
262252 #[ test]
263253 fn test_get_nonexistent_vector ( ) {
264- let ( db, path ) = create_test_db ( ) ;
254+ let ( db, _temp_dir ) = create_test_db ( ) ;
265255 let id = Uuid :: new_v4 ( ) ;
266256
267257 assert_eq ! ( db. get_vector( id) . unwrap( ) , None ) ;
268-
269- std:: fs:: remove_dir_all ( path) . unwrap_or_default ( ) ;
270258 }
271259
272260 #[ test]
273261 fn test_get_nonexistent_payload ( ) {
274- let ( db, path ) = create_test_db ( ) ;
262+ let ( db, _temp_dir ) = create_test_db ( ) ;
275263 let id = Uuid :: new_v4 ( ) ;
276264
277265 assert_eq ! ( db. get_payload( id) . unwrap( ) , None ) ;
278-
279- std:: fs:: remove_dir_all ( path) . unwrap_or_default ( ) ;
280266 }
281267}
0 commit comments