MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_range_errors

Function test_range_errors

src/repr/src/row.rs:4028–4098  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4026
4027 #[mz_ore::test]
4028 fn test_range_errors() {
4029 fn test_range_errors_inner<'a>(
4030 datums: Vec<Vec<Datum<'a>>>,
4031 ) -> Result<(), InvalidRangeError> {
4032 let mut row = Row::default();
4033 let row_len = row.byte_len();
4034 let mut packer = row.packer();
4035 let r = packer.push_range_with(
4036 RangeLowerBound {
4037 inclusive: true,
4038 bound: Some(|row: &mut RowPacker| {
4039 for d in &datums[0] {
4040 row.push(d);
4041 }
4042 Ok(())
4043 }),
4044 },
4045 RangeUpperBound {
4046 inclusive: true,
4047 bound: Some(|row: &mut RowPacker| {
4048 for d in &datums[1] {
4049 row.push(d);
4050 }
4051 Ok(())
4052 }),
4053 },
4054 );
4055
4056 assert_eq!(row_len, row.byte_len());
4057
4058 r
4059 }
4060
4061 // A finite bound whose closure pushes zero values violates the
4062 // `push_range_with` caller contract and still panics. This is
4063 // unreachable when decoding a `ProtoRow`: each decoded bound pushes
4064 // exactly one datum (or fails), so only an in-process caller can hit it.
4065 for panicking_case in [
4066 vec![vec![Datum::Int32(1)], vec![]],
4067 vec![vec![Datum::Int32(1), Datum::Int32(2)], vec![]],
4068 ] {
4069 #[allow(clippy::disallowed_methods)] // not using enhanced panic handler in tests
4070 let result = std::panic::catch_unwind(|| test_range_errors_inner(panicking_case));
4071 assert_err!(result);
4072 }
4073
4074 // Inconsistent bound counts, mismatched datum kinds, and Null bounds are
4075 // all reachable from a crafted/corrupted `ProtoRow`, so they return an
4076 // error instead of panicking.
4077 for error_case in [
4078 vec![
4079 vec![Datum::Int32(1), Datum::Int32(2)],
4080 vec![Datum::Int32(3)],
4081 ],
4082 vec![
4083 vec![Datum::Int32(1)],
4084 vec![Datum::Int32(2), Datum::Int32(3)],
4085 ],

Callers

nothing calls this directly

Calls 2

catch_unwindFunction · 0.85
test_range_errors_innerFunction · 0.85

Tested by

no test coverage detected