Skip to content

Commit

Permalink
dev: add should_panic expected message to tracker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Sep 5, 2023
1 parent 2fa3742 commit 089fb48
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/servers/udp/connection_cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic = "InvalidConnectionId"]
fn it_should_be_not_valid_after_their_last_time_extent() {
let remote_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0);

Expand Down
16 changes: 11 additions & 5 deletions src/tracker/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ impl Id {
/// Will panic if byte slice does not contains the exact amount of bytes need for the `Id`.
#[must_use]
pub fn from_bytes(bytes: &[u8]) -> Self {
assert_eq!(bytes.len(), PEER_ID_BYTES_LEN);
assert_eq!(
PEER_ID_BYTES_LEN,
bytes.len(),
"we are testing the equality of the constant: `PEER_ID_BYTES_LEN` ({}) and the supplied `bytes` length: {}",
PEER_ID_BYTES_LEN,
bytes.len(),
);
let mut ret = Self([0u8; PEER_ID_BYTES_LEN]);
ret.0.clone_from_slice(bytes);
ret
Expand Down Expand Up @@ -363,14 +369,14 @@ mod test {
}

#[test]
#[should_panic]
#[should_panic = "we are testing the equality of the constant: `PEER_ID_BYTES_LEN` (20) and the supplied `bytes` length: 19"]
fn should_fail_trying_to_instantiate_from_a_byte_slice_with_less_than_20_bytes() {
let less_than_20_bytes = [0; 19];
let _: peer::Id = peer::Id::from_bytes(&less_than_20_bytes);
}

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

#[test]
#[should_panic]
#[should_panic = "NotEnoughBytes"]
fn should_fail_trying_to_convert_from_a_byte_vector_with_less_than_20_bytes() {
let _: peer::Id = peer::Id::try_from([0; 19].to_vec()).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "TooManyBytes"]
fn should_fail_trying_to_convert_from_a_byte_vector_with_more_than_20_bytes() {
let _: peer::Id = peer::Id::try_from([0; 21].to_vec()).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/servers/api/v1/contract/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use torrust_tracker_test_helpers::configuration;
use crate::servers::api::test_environment::stopped_test_environment;

#[tokio::test]
#[should_panic]
#[should_panic = "Could not receive bind_address."]
async fn should_fail_with_ssl_enabled_and_bad_ssl_config() {
let mut test_env = stopped_test_environment(configuration::ephemeral());

Expand Down

0 comments on commit 089fb48

Please sign in to comment.