Refactor bucket storage bad header size test (#33091)

This commit is contained in:
Brooks 2023-08-31 13:01:20 -04:00 committed by GitHub
parent 92a0b310c1
commit f8789c79a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 31 deletions

View File

@ -509,8 +509,15 @@ mod test {
assert!(storage.is_free(ix)); assert!(storage.is_free(ix));
} }
struct BucketBadHeader {} #[test]
#[should_panic]
fn test_header_bad_size() {
struct BucketBadHeader;
impl BucketCapacity for BucketBadHeader {
fn capacity(&self) -> u64 {
unimplemented!();
}
}
impl BucketOccupied for BucketBadHeader { impl BucketOccupied for BucketBadHeader {
fn occupy(&mut self, _element: &mut [u8], _ix: usize) { fn occupy(&mut self, _element: &mut [u8], _ix: usize) {
unimplemented!(); unimplemented!();
@ -525,22 +532,13 @@ mod test {
// not multiple of u64 // not multiple of u64
std::mem::size_of::<u64>() - 1 std::mem::size_of::<u64>() - 1
} }
/// initialize this struct
fn new(_num_elements: Capacity) -> Self { fn new(_num_elements: Capacity) -> Self {
Self {} Self
} }
} }
impl BucketCapacity for BucketBadHeader { // ensure we panic if the header size (i.e. offset to first data) is not aligned to eight bytes
fn capacity(&self) -> u64 { BucketStorage::<BucketBadHeader>::new_with_capacity(
unimplemented!();
}
}
#[test]
#[should_panic(expected = "assertion failed: `(left == right)`")]
fn test_header_size() {
_ = BucketStorage::<BucketBadHeader>::new_with_capacity(
Arc::default(), Arc::default(),
0, 0,
0, 0,