Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions contrib/bencode/src/reference/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,69 +329,68 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidByte { pos: 0 }"]
fn negative_decode_bytes_neg_len() {
BencodeRef::decode(BYTES_NEG_LEN, BDecodeOpt::default()).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(BytesEmpty { pos: 20 }"]
fn negative_decode_bytes_extra() {
BencodeRef::decode(BYTES_EXTRA, BDecodeOpt::default()).unwrap();
}

#[test]
#[should_panic]
fn negative_decode_bytes_not_utf8() {
let bencode = BencodeRef::decode(BYTES_NOT_UTF8, BDecodeOpt::default()).unwrap();

bencode.str().unwrap();
assert!(bencode.str().is_none());
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntParseError { pos: 1 }"]
fn negative_decode_int_nan() {
super::decode_int(INT_NAN, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntZeroPadding { pos: 1 }"]
fn negative_decode_int_leading_zero() {
super::decode_int(INT_LEADING_ZERO, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntZeroPadding { pos: 1 }"]
fn negative_decode_int_double_zero() {
super::decode_int(INT_DOUBLE_ZERO, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntNegativeZero { pos: 1 }"]
fn negative_decode_int_negative_zero() {
super::decode_int(INT_NEGATIVE_ZERO, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = " BencodeParseError(InvalidIntParseError { pos: 1 }"]
fn negative_decode_int_double_negative() {
super::decode_int(INT_DOUBLE_NEGATIVE, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidKeyOrdering { pos: 15, key: [97, 95, 107, 101, 121] }"]
fn negative_decode_dict_unordered_keys() {
BencodeRef::decode(DICT_UNORDERED_KEYS, BDecodeOpt::new(5, true, true)).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidKeyDuplicates { pos: 18, key: [97, 95, 107, 101, 121] }"]
fn negative_decode_dict_dup_keys_same_data() {
BencodeRef::decode(DICT_DUP_KEYS_SAME_DATA, BDecodeOpt::default()).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidKeyDuplicates { pos: 18, key: [97, 95, 107, 101, 121] }"]
fn negative_decode_dict_dup_keys_diff_data() {
BencodeRef::decode(DICT_DUP_KEYS_DIFF_DATA, BDecodeOpt::default()).unwrap();
}
Expand Down
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
3 changes: 2 additions & 1 deletion tests/servers/api/v1/contract/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use torrust_tracker_test_helpers::configuration;
use crate::servers::api::test_environment::stopped_test_environment;

#[tokio::test]
#[should_panic]
#[ignore]
#[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