Skip to content

Commit 80d7f1b

Browse files
committed
refactor: add loggin setup to all integration tests
1 parent aca7fc0 commit 80d7f1b

File tree

11 files changed

+235
-30
lines changed

11 files changed

+235
-30
lines changed

tests/common/logging.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ pub fn captured_logs_buffer() -> &'static Mutex<CircularBuffer> {
1616
CAPTURED_LOGS_GLOBAL_BUFFER.get_or_init(|| Mutex::new(CircularBuffer::new(1000, 200)))
1717
}
1818

19-
pub fn setup(filter: LevelFilter) {
19+
pub fn setup() {
2020
INIT.call_once(|| {
21-
tracing_init(filter, &TraceStyle::Default);
21+
tracing_init(LevelFilter::ERROR, &TraceStyle::Default);
2222
});
2323
}
2424

tests/servers/api/v1/contract/authentication.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use torrust_tracker_test_helpers::configuration;
2-
use tracing::level_filters::LevelFilter;
32

43
use crate::common::http::{Query, QueryParam};
54
use crate::common::logging::{self};
@@ -9,6 +8,8 @@ use crate::servers::api::Started;
98

109
#[tokio::test]
1110
async fn should_authenticate_requests_by_using_a_token_query_param() {
11+
logging::setup();
12+
1213
let env = Started::new(&configuration::ephemeral().into()).await;
1314

1415
let token = env.get_connection_info().api_token.unwrap();
@@ -24,7 +25,7 @@ async fn should_authenticate_requests_by_using_a_token_query_param() {
2425

2526
#[tokio::test]
2627
async fn should_not_authenticate_requests_when_the_token_is_missing() {
27-
logging::setup(LevelFilter::ERROR);
28+
logging::setup();
2829

2930
let env = Started::new(&configuration::ephemeral().into()).await;
3031

@@ -39,7 +40,7 @@ async fn should_not_authenticate_requests_when_the_token_is_missing() {
3940

4041
#[tokio::test]
4142
async fn should_not_authenticate_requests_when_the_token_is_empty() {
42-
logging::setup(LevelFilter::ERROR);
43+
logging::setup();
4344

4445
let env = Started::new(&configuration::ephemeral().into()).await;
4546

@@ -54,7 +55,7 @@ async fn should_not_authenticate_requests_when_the_token_is_empty() {
5455

5556
#[tokio::test]
5657
async fn should_not_authenticate_requests_when_the_token_is_invalid() {
57-
logging::setup(LevelFilter::ERROR);
58+
logging::setup();
5859

5960
let env = Started::new(&configuration::ephemeral().into()).await;
6061

@@ -69,6 +70,8 @@ async fn should_not_authenticate_requests_when_the_token_is_invalid() {
6970

7071
#[tokio::test]
7172
async fn should_allow_the_token_query_param_to_be_at_any_position_in_the_url_query() {
73+
logging::setup();
74+
7275
let env = Started::new(&configuration::ephemeral().into()).await;
7376

7477
let token = env.get_connection_info().api_token.unwrap();

tests/servers/api/v1/contract/context/auth_key.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::time::Duration;
33
use serde::Serialize;
44
use torrust_tracker::core::auth::Key;
55
use torrust_tracker_test_helpers::configuration;
6-
use tracing::level_filters::LevelFilter;
76

87
use crate::common::logging::{self};
98
use crate::servers::api::connection_info::{connection_with_invalid_token, connection_with_no_token};
@@ -17,6 +16,8 @@ use crate::servers::api::{force_database_error, Started};
1716

1817
#[tokio::test]
1918
async fn should_allow_generating_a_new_random_auth_key() {
19+
logging::setup();
20+
2021
let env = Started::new(&configuration::ephemeral().into()).await;
2122

2223
let response = Client::new(env.get_connection_info())
@@ -39,6 +40,8 @@ async fn should_allow_generating_a_new_random_auth_key() {
3940

4041
#[tokio::test]
4142
async fn should_allow_uploading_a_preexisting_auth_key() {
43+
logging::setup();
44+
4245
let env = Started::new(&configuration::ephemeral().into()).await;
4346

4447
let response = Client::new(env.get_connection_info())
@@ -61,7 +64,7 @@ async fn should_allow_uploading_a_preexisting_auth_key() {
6164

6265
#[tokio::test]
6366
async fn should_not_allow_generating_a_new_auth_key_for_unauthenticated_users() {
64-
logging::setup(LevelFilter::ERROR);
67+
logging::setup();
6568

6669
let env = Started::new(&configuration::ephemeral().into()).await;
6770

@@ -88,7 +91,7 @@ async fn should_not_allow_generating_a_new_auth_key_for_unauthenticated_users()
8891

8992
#[tokio::test]
9093
async fn should_fail_when_the_auth_key_cannot_be_generated() {
91-
logging::setup(LevelFilter::ERROR);
94+
logging::setup();
9295

9396
let env = Started::new(&configuration::ephemeral().into()).await;
9497

@@ -108,6 +111,8 @@ async fn should_fail_when_the_auth_key_cannot_be_generated() {
108111

109112
#[tokio::test]
110113
async fn should_allow_deleting_an_auth_key() {
114+
logging::setup();
115+
111116
let env = Started::new(&configuration::ephemeral().into()).await;
112117

113118
let seconds_valid = 60;
@@ -135,6 +140,8 @@ async fn should_fail_generating_a_new_auth_key_when_the_provided_key_is_invalid(
135140
pub seconds_valid: u64,
136141
}
137142

143+
logging::setup();
144+
138145
let env = Started::new(&configuration::ephemeral().into()).await;
139146

140147
let invalid_keys = [
@@ -172,6 +179,8 @@ async fn should_fail_generating_a_new_auth_key_when_the_key_duration_is_invalid(
172179
pub seconds_valid: String,
173180
}
174181

182+
logging::setup();
183+
175184
let env = Started::new(&configuration::ephemeral().into()).await;
176185

177186
let invalid_key_durations = [
@@ -199,6 +208,8 @@ async fn should_fail_generating_a_new_auth_key_when_the_key_duration_is_invalid(
199208

200209
#[tokio::test]
201210
async fn should_fail_deleting_an_auth_key_when_the_key_id_is_invalid() {
211+
logging::setup();
212+
202213
let env = Started::new(&configuration::ephemeral().into()).await;
203214

204215
let invalid_auth_keys = [
@@ -222,7 +233,7 @@ async fn should_fail_deleting_an_auth_key_when_the_key_id_is_invalid() {
222233

223234
#[tokio::test]
224235
async fn should_fail_when_the_auth_key_cannot_be_deleted() {
225-
logging::setup(LevelFilter::ERROR);
236+
logging::setup();
226237

227238
let env = Started::new(&configuration::ephemeral().into()).await;
228239

@@ -246,7 +257,7 @@ async fn should_fail_when_the_auth_key_cannot_be_deleted() {
246257

247258
#[tokio::test]
248259
async fn should_not_allow_deleting_an_auth_key_for_unauthenticated_users() {
249-
logging::setup(LevelFilter::ERROR);
260+
logging::setup();
250261

251262
let env = Started::new(&configuration::ephemeral().into()).await;
252263

@@ -283,6 +294,8 @@ async fn should_not_allow_deleting_an_auth_key_for_unauthenticated_users() {
283294

284295
#[tokio::test]
285296
async fn should_allow_reloading_keys() {
297+
logging::setup();
298+
286299
let env = Started::new(&configuration::ephemeral().into()).await;
287300

288301
let seconds_valid = 60;
@@ -300,7 +313,7 @@ async fn should_allow_reloading_keys() {
300313

301314
#[tokio::test]
302315
async fn should_fail_when_keys_cannot_be_reloaded() {
303-
logging::setup(LevelFilter::ERROR);
316+
logging::setup();
304317

305318
let env = Started::new(&configuration::ephemeral().into()).await;
306319

@@ -321,7 +334,7 @@ async fn should_fail_when_keys_cannot_be_reloaded() {
321334

322335
#[tokio::test]
323336
async fn should_not_allow_reloading_keys_for_unauthenticated_users() {
324-
logging::setup(LevelFilter::ERROR);
337+
logging::setup();
325338

326339
let env = Started::new(&configuration::ephemeral().into()).await;
327340

@@ -350,7 +363,6 @@ mod deprecated_generate_key_endpoint {
350363

351364
use torrust_tracker::core::auth::Key;
352365
use torrust_tracker_test_helpers::configuration;
353-
use tracing::level_filters::LevelFilter;
354366

355367
use crate::common::logging::{self};
356368
use crate::servers::api::connection_info::{connection_with_invalid_token, connection_with_no_token};
@@ -363,6 +375,8 @@ mod deprecated_generate_key_endpoint {
363375

364376
#[tokio::test]
365377
async fn should_allow_generating_a_new_auth_key() {
378+
logging::setup();
379+
366380
let env = Started::new(&configuration::ephemeral().into()).await;
367381

368382
let seconds_valid = 60;
@@ -382,7 +396,7 @@ mod deprecated_generate_key_endpoint {
382396

383397
#[tokio::test]
384398
async fn should_not_allow_generating_a_new_auth_key_for_unauthenticated_users() {
385-
logging::setup(LevelFilter::ERROR);
399+
logging::setup();
386400

387401
let env = Started::new(&configuration::ephemeral().into()).await;
388402

@@ -405,6 +419,8 @@ mod deprecated_generate_key_endpoint {
405419

406420
#[tokio::test]
407421
async fn should_fail_generating_a_new_auth_key_when_the_key_duration_is_invalid() {
422+
logging::setup();
423+
408424
let env = Started::new(&configuration::ephemeral().into()).await;
409425

410426
let invalid_key_durations = [
@@ -426,7 +442,7 @@ mod deprecated_generate_key_endpoint {
426442

427443
#[tokio::test]
428444
async fn should_fail_when_the_auth_key_cannot_be_generated() {
429-
logging::setup(LevelFilter::ERROR);
445+
logging::setup();
430446

431447
let env = Started::new(&configuration::ephemeral().into()).await;
432448

tests/servers/api/v1/contract/context/health_check.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use torrust_tracker::servers::apis::v1::context::health_check::resources::{Report, Status};
22
use torrust_tracker_test_helpers::configuration;
33

4+
use crate::common::logging;
45
use crate::servers::api::v1::client::get;
56
use crate::servers::api::Started;
67

78
#[tokio::test]
89
async fn health_check_endpoint_should_return_status_ok_if_api_is_running() {
10+
logging::setup();
11+
912
let env = Started::new(&configuration::ephemeral().into()).await;
1013

1114
let url = format!("http://{}/api/health_check", env.get_connection_info().bind_address);

tests/servers/api/v1/contract/context/stats.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use bittorrent_primitives::info_hash::InfoHash;
44
use torrust_tracker::servers::apis::v1::context::stats::resources::Stats;
55
use torrust_tracker_primitives::peer::fixture::PeerBuilder;
66
use torrust_tracker_test_helpers::configuration;
7-
use tracing::level_filters::LevelFilter;
87

98
use crate::common::logging::{self};
109
use crate::servers::api::connection_info::{connection_with_invalid_token, connection_with_no_token};
@@ -14,6 +13,8 @@ use crate::servers::api::Started;
1413

1514
#[tokio::test]
1615
async fn should_allow_getting_tracker_statistics() {
16+
logging::setup();
17+
1718
let env = Started::new(&configuration::ephemeral().into()).await;
1819

1920
env.add_torrent_peer(
@@ -60,7 +61,7 @@ async fn should_allow_getting_tracker_statistics() {
6061

6162
#[tokio::test]
6263
async fn should_not_allow_getting_tracker_statistics_for_unauthenticated_users() {
63-
logging::setup(LevelFilter::ERROR);
64+
logging::setup();
6465

6566
let env = Started::new(&configuration::ephemeral().into()).await;
6667

tests/servers/api/v1/contract/context/torrent.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use torrust_tracker::servers::apis::v1::context::torrent::resources::peer::Peer;
55
use torrust_tracker::servers::apis::v1::context::torrent::resources::torrent::{self, Torrent};
66
use torrust_tracker_primitives::peer::fixture::PeerBuilder;
77
use torrust_tracker_test_helpers::configuration;
8-
use tracing::level_filters::LevelFilter;
98

109
use crate::common::http::{Query, QueryParam};
1110
use crate::common::logging::{self};
@@ -22,6 +21,8 @@ use crate::servers::api::Started;
2221

2322
#[tokio::test]
2423
async fn should_allow_getting_all_torrents() {
24+
logging::setup();
25+
2526
let env = Started::new(&configuration::ephemeral().into()).await;
2627

2728
let info_hash = InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap();
@@ -46,6 +47,8 @@ async fn should_allow_getting_all_torrents() {
4647

4748
#[tokio::test]
4849
async fn should_allow_limiting_the_torrents_in_the_result() {
50+
logging::setup();
51+
4952
let env = Started::new(&configuration::ephemeral().into()).await;
5053

5154
// torrents are ordered alphabetically by infohashes
@@ -75,6 +78,8 @@ async fn should_allow_limiting_the_torrents_in_the_result() {
7578

7679
#[tokio::test]
7780
async fn should_allow_the_torrents_result_pagination() {
81+
logging::setup();
82+
7883
let env = Started::new(&configuration::ephemeral().into()).await;
7984

8085
// torrents are ordered alphabetically by infohashes
@@ -104,6 +109,8 @@ async fn should_allow_the_torrents_result_pagination() {
104109

105110
#[tokio::test]
106111
async fn should_allow_getting_a_list_of_torrents_providing_infohashes() {
112+
logging::setup();
113+
107114
let env = Started::new(&configuration::ephemeral().into()).await;
108115

109116
let info_hash_1 = InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap(); // DevSkim: ignore DS173237
@@ -146,6 +153,8 @@ async fn should_allow_getting_a_list_of_torrents_providing_infohashes() {
146153

147154
#[tokio::test]
148155
async fn should_fail_getting_torrents_when_the_offset_query_parameter_cannot_be_parsed() {
156+
logging::setup();
157+
149158
let env = Started::new(&configuration::ephemeral().into()).await;
150159

151160
let invalid_offsets = [" ", "-1", "1.1", "INVALID OFFSET"];
@@ -163,6 +172,8 @@ async fn should_fail_getting_torrents_when_the_offset_query_parameter_cannot_be_
163172

164173
#[tokio::test]
165174
async fn should_fail_getting_torrents_when_the_limit_query_parameter_cannot_be_parsed() {
175+
logging::setup();
176+
166177
let env = Started::new(&configuration::ephemeral().into()).await;
167178

168179
let invalid_limits = [" ", "-1", "1.1", "INVALID LIMIT"];
@@ -180,6 +191,8 @@ async fn should_fail_getting_torrents_when_the_limit_query_parameter_cannot_be_p
180191

181192
#[tokio::test]
182193
async fn should_fail_getting_torrents_when_the_info_hash_parameter_is_invalid() {
194+
logging::setup();
195+
183196
let env = Started::new(&configuration::ephemeral().into()).await;
184197

185198
let invalid_info_hashes = [" ", "-1", "1.1", "INVALID INFO_HASH"];
@@ -201,7 +214,7 @@ async fn should_fail_getting_torrents_when_the_info_hash_parameter_is_invalid()
201214

202215
#[tokio::test]
203216
async fn should_not_allow_getting_torrents_for_unauthenticated_users() {
204-
logging::setup(LevelFilter::ERROR);
217+
logging::setup();
205218

206219
let env = Started::new(&configuration::ephemeral().into()).await;
207220

@@ -222,6 +235,8 @@ async fn should_not_allow_getting_torrents_for_unauthenticated_users() {
222235

223236
#[tokio::test]
224237
async fn should_allow_getting_a_torrent_info() {
238+
logging::setup();
239+
225240
let env = Started::new(&configuration::ephemeral().into()).await;
226241

227242
let info_hash = InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap();
@@ -251,6 +266,8 @@ async fn should_allow_getting_a_torrent_info() {
251266

252267
#[tokio::test]
253268
async fn should_fail_while_getting_a_torrent_info_when_the_torrent_does_not_exist() {
269+
logging::setup();
270+
254271
let env = Started::new(&configuration::ephemeral().into()).await;
255272

256273
let info_hash = InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap();
@@ -266,6 +283,8 @@ async fn should_fail_while_getting_a_torrent_info_when_the_torrent_does_not_exis
266283

267284
#[tokio::test]
268285
async fn should_fail_getting_a_torrent_info_when_the_provided_infohash_is_invalid() {
286+
logging::setup();
287+
269288
let env = Started::new(&configuration::ephemeral().into()).await;
270289

271290
for invalid_infohash in &invalid_infohashes_returning_bad_request() {
@@ -285,7 +304,7 @@ async fn should_fail_getting_a_torrent_info_when_the_provided_infohash_is_invali
285304

286305
#[tokio::test]
287306
async fn should_not_allow_getting_a_torrent_info_for_unauthenticated_users() {
288-
logging::setup(LevelFilter::ERROR);
307+
logging::setup();
289308

290309
let env = Started::new(&configuration::ephemeral().into()).await;
291310

0 commit comments

Comments
 (0)