Skip to content

Commit 21c865d

Browse files
committed
test: [#1240] add tests for bittorrent_tracker_core::torrent::services
1 parent ef87954 commit 21c865d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/tracker-core/src/torrent/services.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,44 @@ mod tests {
297297
);
298298
}
299299
}
300+
301+
mod getting_basic_torrent_info_for_multiple_torrents_at_once {
302+
303+
use std::sync::Arc;
304+
305+
use crate::core_tests::sample_info_hash;
306+
use crate::torrent::repository::in_memory::InMemoryTorrentRepository;
307+
use crate::torrent::services::tests::sample_peer;
308+
use crate::torrent::services::{get_torrents, BasicInfo};
309+
310+
#[tokio::test]
311+
async fn it_should_return_an_empty_list_if_none_of_the_requested_torrents_is_found() {
312+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
313+
314+
let torrent_info = get_torrents(&in_memory_torrent_repository, &[sample_info_hash()]);
315+
316+
assert!(torrent_info.is_empty());
317+
}
318+
319+
#[tokio::test]
320+
async fn it_should_return_a_list_with_basic_info_about_the_requested_torrents() {
321+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
322+
323+
let info_hash = sample_info_hash();
324+
325+
let () = in_memory_torrent_repository.upsert_peer(&info_hash, &sample_peer());
326+
327+
let torrent_info = get_torrents(&in_memory_torrent_repository, &[info_hash]);
328+
329+
assert_eq!(
330+
torrent_info,
331+
vec!(BasicInfo {
332+
info_hash,
333+
seeders: 1,
334+
completed: 0,
335+
leechers: 0,
336+
})
337+
);
338+
}
339+
}
300340
}

0 commit comments

Comments
 (0)