Skip to content

Commit 089fb48

Browse files
committed
dev: add should_panic expected message to tracker tests
1 parent 2fa3742 commit 089fb48

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/servers/udp/connection_cookie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ mod tests {
314314
}
315315

316316
#[test]
317-
#[should_panic]
317+
#[should_panic = "InvalidConnectionId"]
318318
fn it_should_be_not_valid_after_their_last_time_extent() {
319319
let remote_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0);
320320

src/tracker/peer.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ impl Id {
150150
/// Will panic if byte slice does not contains the exact amount of bytes need for the `Id`.
151151
#[must_use]
152152
pub fn from_bytes(bytes: &[u8]) -> Self {
153-
assert_eq!(bytes.len(), PEER_ID_BYTES_LEN);
153+
assert_eq!(
154+
PEER_ID_BYTES_LEN,
155+
bytes.len(),
156+
"we are testing the equality of the constant: `PEER_ID_BYTES_LEN` ({}) and the supplied `bytes` length: {}",
157+
PEER_ID_BYTES_LEN,
158+
bytes.len(),
159+
);
154160
let mut ret = Self([0u8; PEER_ID_BYTES_LEN]);
155161
ret.0.clone_from_slice(bytes);
156162
ret
@@ -363,14 +369,14 @@ mod test {
363369
}
364370

365371
#[test]
366-
#[should_panic]
372+
#[should_panic = "we are testing the equality of the constant: `PEER_ID_BYTES_LEN` (20) and the supplied `bytes` length: 19"]
367373
fn should_fail_trying_to_instantiate_from_a_byte_slice_with_less_than_20_bytes() {
368374
let less_than_20_bytes = [0; 19];
369375
let _: peer::Id = peer::Id::from_bytes(&less_than_20_bytes);
370376
}
371377

372378
#[test]
373-
#[should_panic]
379+
#[should_panic = "we are testing the equality of the constant: `PEER_ID_BYTES_LEN` (20) and the supplied `bytes` length: 21"]
374380
fn should_fail_trying_to_instantiate_from_a_byte_slice_with_more_than_20_bytes() {
375381
let more_than_20_bytes = [0; 21];
376382
let _: peer::Id = peer::Id::from_bytes(&more_than_20_bytes);
@@ -418,13 +424,13 @@ mod test {
418424
}
419425

420426
#[test]
421-
#[should_panic]
427+
#[should_panic = "NotEnoughBytes"]
422428
fn should_fail_trying_to_convert_from_a_byte_vector_with_less_than_20_bytes() {
423429
let _: peer::Id = peer::Id::try_from([0; 19].to_vec()).unwrap();
424430
}
425431

426432
#[test]
427-
#[should_panic]
433+
#[should_panic = "TooManyBytes"]
428434
fn should_fail_trying_to_convert_from_a_byte_vector_with_more_than_20_bytes() {
429435
let _: peer::Id = peer::Id::try_from([0; 21].to_vec()).unwrap();
430436
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use torrust_tracker_test_helpers::configuration;
33
use crate::servers::api::test_environment::stopped_test_environment;
44

55
#[tokio::test]
6-
#[should_panic]
6+
#[should_panic = "Could not receive bind_address."]
77
async fn should_fail_with_ssl_enabled_and_bad_ssl_config() {
88
let mut test_env = stopped_test_environment(configuration::ephemeral());
99

0 commit comments

Comments
 (0)