@@ -107,10 +107,37 @@ pub async fn get_torrents(tracker: Arc<Tracker>, info_hashes: &[InfoHash]) -> Ve
107
107
#[ cfg( test) ]
108
108
mod tests {
109
109
use std:: net:: { IpAddr , Ipv4Addr , SocketAddr } ;
110
+ use std:: sync:: Arc ;
110
111
111
112
use aquatic_udp_protocol:: { AnnounceEvent , NumberOfBytes , PeerId } ;
113
+ use torrust_tracker_configuration:: Configuration ;
112
114
use torrust_tracker_primitives:: { peer, DurationSinceUnixEpoch } ;
113
115
116
+ use crate :: app_test:: initialize_tracker_dependencies;
117
+ use crate :: core:: services:: initialize_tracker;
118
+ use crate :: core:: Tracker ;
119
+
120
+ fn initialize_tracker_and_deps ( config : & Configuration ) -> Arc < Tracker > {
121
+ let (
122
+ database,
123
+ _in_memory_whitelist,
124
+ whitelist_authorization,
125
+ _authentication_service,
126
+ in_memory_torrent_repository,
127
+ db_torrent_repository,
128
+ torrents_manager,
129
+ ) = initialize_tracker_dependencies ( config) ;
130
+
131
+ Arc :: new ( initialize_tracker (
132
+ config,
133
+ & database,
134
+ & whitelist_authorization,
135
+ & in_memory_torrent_repository,
136
+ & db_torrent_repository,
137
+ & torrents_manager,
138
+ ) )
139
+ }
140
+
114
141
fn sample_peer ( ) -> peer:: Peer {
115
142
peer:: Peer {
116
143
peer_id : PeerId ( * b"-qB00000000000000000" ) ,
@@ -134,7 +161,7 @@ mod tests {
134
161
135
162
use crate :: app_test:: initialize_tracker_dependencies;
136
163
use crate :: core:: services:: initialize_tracker;
137
- use crate :: core:: services:: torrent:: tests:: sample_peer;
164
+ use crate :: core:: services:: torrent:: tests:: { initialize_tracker_and_deps , sample_peer} ;
138
165
use crate :: core:: services:: torrent:: { get_torrent_info, Info } ;
139
166
140
167
pub fn tracker_configuration ( ) -> Configuration {
@@ -179,24 +206,7 @@ mod tests {
179
206
async fn should_return_the_torrent_info_if_the_tracker_has_the_torrent ( ) {
180
207
let config = tracker_configuration ( ) ;
181
208
182
- let (
183
- database,
184
- _in_memory_whitelist,
185
- whitelist_authorization,
186
- _authentication_service,
187
- in_memory_torrent_repository,
188
- db_torrent_repository,
189
- torrents_manager,
190
- ) = initialize_tracker_dependencies ( & config) ;
191
-
192
- let tracker = Arc :: new ( initialize_tracker (
193
- & config,
194
- & database,
195
- & whitelist_authorization,
196
- & in_memory_torrent_repository,
197
- & db_torrent_repository,
198
- & torrents_manager,
199
- ) ) ;
209
+ let tracker = initialize_tracker_and_deps ( & config) ;
200
210
201
211
let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d" . to_owned ( ) ;
202
212
let info_hash = InfoHash :: from_str ( & hash) . unwrap ( ) ;
@@ -220,15 +230,12 @@ mod tests {
220
230
mod searching_for_torrents {
221
231
222
232
use std:: str:: FromStr ;
223
- use std:: sync:: Arc ;
224
233
225
234
use bittorrent_primitives:: info_hash:: InfoHash ;
226
235
use torrust_tracker_configuration:: Configuration ;
227
236
use torrust_tracker_test_helpers:: configuration;
228
237
229
- use crate :: app_test:: initialize_tracker_dependencies;
230
- use crate :: core:: services:: initialize_tracker;
231
- use crate :: core:: services:: torrent:: tests:: sample_peer;
238
+ use crate :: core:: services:: torrent:: tests:: { initialize_tracker_and_deps, sample_peer} ;
232
239
use crate :: core:: services:: torrent:: { get_torrents_page, BasicInfo , Pagination } ;
233
240
234
241
pub fn tracker_configuration ( ) -> Configuration {
@@ -239,24 +246,7 @@ mod tests {
239
246
async fn should_return_an_empty_result_if_the_tracker_does_not_have_any_torrent ( ) {
240
247
let config = tracker_configuration ( ) ;
241
248
242
- let (
243
- database,
244
- _in_memory_whitelist,
245
- whitelist_authorization,
246
- _authentication_service,
247
- in_memory_torrent_repository,
248
- db_torrent_repository,
249
- torrents_manager,
250
- ) = initialize_tracker_dependencies ( & config) ;
251
-
252
- let tracker = Arc :: new ( initialize_tracker (
253
- & config,
254
- & database,
255
- & whitelist_authorization,
256
- & in_memory_torrent_repository,
257
- & db_torrent_repository,
258
- & torrents_manager,
259
- ) ) ;
249
+ let tracker = initialize_tracker_and_deps ( & config) ;
260
250
261
251
let torrents = get_torrents_page ( tracker. clone ( ) , Some ( & Pagination :: default ( ) ) ) . await ;
262
252
@@ -267,24 +257,7 @@ mod tests {
267
257
async fn should_return_a_summarized_info_for_all_torrents ( ) {
268
258
let config = tracker_configuration ( ) ;
269
259
270
- let (
271
- database,
272
- _in_memory_whitelist,
273
- whitelist_authorization,
274
- _authentication_service,
275
- in_memory_torrent_repository,
276
- db_torrent_repository,
277
- torrents_manager,
278
- ) = initialize_tracker_dependencies ( & config) ;
279
-
280
- let tracker = Arc :: new ( initialize_tracker (
281
- & config,
282
- & database,
283
- & whitelist_authorization,
284
- & in_memory_torrent_repository,
285
- & db_torrent_repository,
286
- & torrents_manager,
287
- ) ) ;
260
+ let tracker = initialize_tracker_and_deps ( & config) ;
288
261
289
262
let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d" . to_owned ( ) ;
290
263
let info_hash = InfoHash :: from_str ( & hash) . unwrap ( ) ;
@@ -308,24 +281,7 @@ mod tests {
308
281
async fn should_allow_limiting_the_number_of_torrents_in_the_result ( ) {
309
282
let config = tracker_configuration ( ) ;
310
283
311
- let (
312
- database,
313
- _in_memory_whitelist,
314
- whitelist_authorization,
315
- _authentication_service,
316
- in_memory_torrent_repository,
317
- db_torrent_repository,
318
- torrents_manager,
319
- ) = initialize_tracker_dependencies ( & config) ;
320
-
321
- let tracker = Arc :: new ( initialize_tracker (
322
- & config,
323
- & database,
324
- & whitelist_authorization,
325
- & in_memory_torrent_repository,
326
- & db_torrent_repository,
327
- & torrents_manager,
328
- ) ) ;
284
+ let tracker = initialize_tracker_and_deps ( & config) ;
329
285
330
286
let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d" . to_owned ( ) ;
331
287
let info_hash1 = InfoHash :: from_str ( & hash1) . unwrap ( ) ;
@@ -347,24 +303,7 @@ mod tests {
347
303
async fn should_allow_using_pagination_in_the_result ( ) {
348
304
let config = tracker_configuration ( ) ;
349
305
350
- let (
351
- database,
352
- _in_memory_whitelist,
353
- whitelist_authorization,
354
- _authentication_service,
355
- in_memory_torrent_repository,
356
- db_torrent_repository,
357
- torrents_manager,
358
- ) = initialize_tracker_dependencies ( & config) ;
359
-
360
- let tracker = Arc :: new ( initialize_tracker (
361
- & config,
362
- & database,
363
- & whitelist_authorization,
364
- & in_memory_torrent_repository,
365
- & db_torrent_repository,
366
- & torrents_manager,
367
- ) ) ;
306
+ let tracker = initialize_tracker_and_deps ( & config) ;
368
307
369
308
let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d" . to_owned ( ) ;
370
309
let info_hash1 = InfoHash :: from_str ( & hash1) . unwrap ( ) ;
@@ -395,24 +334,7 @@ mod tests {
395
334
async fn should_return_torrents_ordered_by_info_hash ( ) {
396
335
let config = tracker_configuration ( ) ;
397
336
398
- let (
399
- database,
400
- _in_memory_whitelist,
401
- whitelist_authorization,
402
- _authentication_service,
403
- in_memory_torrent_repository,
404
- db_torrent_repository,
405
- torrents_manager,
406
- ) = initialize_tracker_dependencies ( & config) ;
407
-
408
- let tracker = Arc :: new ( initialize_tracker (
409
- & config,
410
- & database,
411
- & whitelist_authorization,
412
- & in_memory_torrent_repository,
413
- & db_torrent_repository,
414
- & torrents_manager,
415
- ) ) ;
337
+ let tracker = initialize_tracker_and_deps ( & config) ;
416
338
417
339
let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d" . to_owned ( ) ;
418
340
let info_hash1 = InfoHash :: from_str ( & hash1) . unwrap ( ) ;
0 commit comments