Skip to content

Commit f3d3495

Browse files
committed
refactor: [torrust#1524] remove duplciate code for tracker core container
1 parent e90585a commit f3d3495

1 file changed

Lines changed: 7 additions & 42 deletions

File tree

packages/tracker-core/tests/integration.rs

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ use std::sync::Arc;
44

55
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes, PeerId};
66
use bittorrent_primitives::info_hash::InfoHash;
7-
use bittorrent_tracker_core::announce_handler::{AnnounceHandler, PeersWanted};
8-
use bittorrent_tracker_core::databases::setup::initialize_database;
9-
use bittorrent_tracker_core::scrape_handler::ScrapeHandler;
10-
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
11-
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
12-
use bittorrent_tracker_core::whitelist;
13-
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
7+
use bittorrent_tracker_core::announce_handler::PeersWanted;
8+
use bittorrent_tracker_core::container::TrackerCoreContainer;
149
use torrust_tracker_configuration::Core;
1510
use torrust_tracker_primitives::peer::Peer;
1611
use torrust_tracker_primitives::DurationSinceUnixEpoch;
1712
use torrust_tracker_test_helpers::configuration::ephemeral_sqlite_database;
13+
use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer;
1814

1915
/// # Panics
2016
///
@@ -59,41 +55,13 @@ fn remote_client_ip() -> IpAddr {
5955
IpAddr::V4(Ipv4Addr::from_str("126.0.0.1").unwrap())
6056
}
6157

62-
struct Container {
63-
pub announce_handler: Arc<AnnounceHandler>,
64-
pub scrape_handler: Arc<ScrapeHandler>,
65-
}
66-
67-
impl Container {
68-
pub fn initialize(config: &Core) -> Self {
69-
let database = initialize_database(config);
70-
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
71-
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
72-
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
73-
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
74-
config,
75-
&in_memory_whitelist.clone(),
76-
));
77-
let announce_handler = Arc::new(AnnounceHandler::new(
78-
config,
79-
&whitelist_authorization,
80-
&in_memory_torrent_repository,
81-
&db_torrent_repository,
82-
));
83-
let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository));
84-
85-
Self {
86-
announce_handler,
87-
scrape_handler,
88-
}
89-
}
90-
}
91-
9258
#[tokio::test]
9359
async fn test_announce_and_scrape_requests() {
94-
let config = ephemeral_configuration();
60+
let config = Arc::new(ephemeral_configuration());
61+
62+
let torrent_repository_container = Arc::new(TorrentRepositoryContainer::initialize(config.tracker_usage_statistics.into()));
9563

96-
let container = Container::initialize(&config);
64+
let container = TrackerCoreContainer::initialize_from(&config, &torrent_repository_container);
9765

9866
let info_hash = sample_info_hash();
9967

@@ -130,6 +98,3 @@ async fn test_announce_and_scrape_requests() {
13098

13199
assert!(scrape_data.files.contains_key(&info_hash));
132100
}
133-
134-
#[test]
135-
fn test_scrape_request() {}

0 commit comments

Comments
 (0)