Skip to content

Commit

Permalink
Add split_off tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Passaro <[email protected]>
  • Loading branch information
passaro committed Oct 26, 2023
1 parent 711d37d commit 02ce1c2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions mountpoint-s3/src/checksums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,23 @@ mod tests {
assert!(matches!(result, Err(IntegrityError::ChecksumMismatch(_, _))));
}

#[test]
fn test_extend_split_off_self_corrupted() {
let corrupted_bytes = Bytes::from_static(b"corrupted data");
let checksum = crc32c::checksum(b"some bytes");
let mut split_off = ChecksummedBytes::new(corrupted_bytes, checksum).split_off(4);
assert!(matches!(
split_off.validate(),
Err(IntegrityError::ChecksumMismatch(_, _))
));

let extend = ChecksummedBytes::from_bytes(Bytes::from_static(b" extended"));
assert!(matches!(extend.validate(), Ok(())));

let result = split_off.extend(extend);
assert!(matches!(result, Err(IntegrityError::ChecksumMismatch(_, _))));
}

#[test]
fn test_extend_other_corrupted() {
let mut checksummed_bytes = ChecksummedBytes::from_bytes(Bytes::from_static(b"some bytes"));
Expand Down Expand Up @@ -400,6 +417,23 @@ mod tests {
assert!(matches!(result, Err(IntegrityError::ChecksumMismatch(_, _))));
}

#[test]
fn test_extend_split_off_other_corrupted() {
let mut checksummed_bytes = ChecksummedBytes::from_bytes(Bytes::from_static(b"some bytes"));
assert!(matches!(checksummed_bytes.validate(), Ok(())));

let corrupted_bytes = Bytes::from_static(b"corrupted data");
let extend_checksum = crc32c::checksum(b" extended");
let split_off = ChecksummedBytes::new(corrupted_bytes, extend_checksum).split_off(4);
assert!(matches!(
split_off.validate(),
Err(IntegrityError::ChecksumMismatch(_, _))
));

let result = checksummed_bytes.extend(split_off);
assert!(matches!(result, Err(IntegrityError::ChecksumMismatch(_, _))));
}

#[test]
fn test_combine_checksums() {
let buf: &[u8] = b"123456789";
Expand Down

0 comments on commit 02ce1c2

Please sign in to comment.