From 02ce1c2bac879eca3204ecc0ab7b59105a58a93d Mon Sep 17 00:00:00 2001 From: Alessandro Passaro Date: Thu, 26 Oct 2023 18:42:37 +0100 Subject: [PATCH] Add split_off tests Signed-off-by: Alessandro Passaro --- mountpoint-s3/src/checksums.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/mountpoint-s3/src/checksums.rs b/mountpoint-s3/src/checksums.rs index 98067a98c..6e24019c0 100644 --- a/mountpoint-s3/src/checksums.rs +++ b/mountpoint-s3/src/checksums.rs @@ -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")); @@ -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";