@@ -127,3 +127,58 @@ impl From<WhitelistError> for UdpScrapeError {
127
127
Self :: TrackerCoreWhitelistError { source : whitelist_error }
128
128
}
129
129
}
130
+
131
+ #[ cfg( test) ]
132
+ mod tests {
133
+ use aquatic_udp_protocol:: { ConnectionId , InfoHash , ScrapeRequest , TransactionId } ;
134
+ use bittorrent_tracker_core:: torrent:: repository:: in_memory:: InMemoryTorrentRepository ;
135
+ use bittorrent_tracker_core:: whitelist;
136
+ use bittorrent_tracker_core:: whitelist:: repository:: in_memory:: InMemoryWhitelist ;
137
+ use torrust_tracker_test_helpers:: configuration;
138
+
139
+ use super :: * ;
140
+ //use crate::connection_cookie::make;
141
+ use crate :: services:: tests:: {
142
+ sample_cookie_valid_range,
143
+ // sample_ipv4_remote_addr_fingerprint,
144
+ // sample_issue_time
145
+ sample_ipv4_remote_addr,
146
+ } ;
147
+ use crate :: statistics:: repository:: Repository ;
148
+
149
+ #[ tokio:: test]
150
+ async fn should_increase_scrape_event_when_handling_scrape ( ) {
151
+ let config = configuration:: ephemeral_public ( ) ;
152
+ let _stats_repository = Repository :: new ( ) ;
153
+ let in_memory_whitelist = Arc :: new ( InMemoryWhitelist :: default ( ) ) ;
154
+ let whitelist_authorization = Arc :: new ( whitelist:: authorization:: WhitelistAuthorization :: new (
155
+ & config. core ,
156
+ & in_memory_whitelist. clone ( ) ,
157
+ ) ) ;
158
+ let in_memory_torrent_repository = Arc :: new ( InMemoryTorrentRepository :: default ( ) ) ;
159
+ let ( udp_core_stats_event_sender, _udp_core_stats_repository) = statistics:: setup:: factory ( false ) ;
160
+ let udp_core_stats_event_sender = Arc :: new ( udp_core_stats_event_sender) ;
161
+ let info_hash = InfoHash ( [ 0u8 ; 20 ] ) ;
162
+ let info_hashes = vec ! [ info_hash] ;
163
+ let request = ScrapeRequest {
164
+ connection_id : ConnectionId ( 0i64 . into ( ) ) ,
165
+ transaction_id : TransactionId ( 0i32 . into ( ) ) ,
166
+ info_hashes,
167
+ } ;
168
+
169
+ let scrape_handler = Arc :: new ( ScrapeHandler :: new ( & whitelist_authorization, & in_memory_torrent_repository) ) ;
170
+ let scrape_service = ScrapeService :: new ( scrape_handler, udp_core_stats_event_sender) ;
171
+ let _result = scrape_service
172
+ . handle_scrape ( sample_ipv4_remote_addr ( ) , & request, sample_cookie_valid_range ( ) )
173
+ . await ;
174
+ /*let _stats = stats_repository.get_stats().await;
175
+ assert_eq!(
176
+ response.unwrap().files.keys().next().unwrap().0,
177
+ info_hash.0,
178
+
179
+ );
180
+ */
181
+ // );
182
+ //assert_eq!(stats.udp4_scrapes_handled, 1)
183
+ }
184
+ }
0 commit comments