Skip to main content

reifydb_sub_flow/operator/stateful/
test_utils.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4pub mod test {
5	use reifydb_abi::operator::capabilities::OperatorCapability;
6	use reifydb_codec::{
7		encoded::{row::EncodedRow, shape::RowShape},
8		key::encoded::EncodedKey,
9	};
10	use reifydb_core::interface::{catalog::flow::FlowNodeId, change::Change};
11	use reifydb_engine::test_harness::TestEngine;
12	use reifydb_transaction::transaction::admin::AdminTransaction;
13	use reifydb_value::{
14		Result,
15		util::cowvec::CowVec,
16		value::{identity::IdentityId, value_type::ValueType},
17	};
18
19	use crate::{operator::Operator, transaction::FlowTransaction};
20
21	pub struct TestOperator {
22		pub id: FlowNodeId,
23		pub layout: RowShape,
24		pub key_types: Vec<ValueType>,
25	}
26
27	impl TestOperator {
28		pub fn new(id: FlowNodeId) -> Self {
29			Self {
30				id,
31				layout: RowShape::testing(&[ValueType::Int8, ValueType::Float8, ValueType::Utf8]),
32				key_types: vec![ValueType::Utf8, ValueType::Int4],
33			}
34		}
35
36		pub fn simple(id: FlowNodeId) -> Self {
37			Self {
38				id,
39				layout: RowShape::testing(&[ValueType::Int8]),
40				key_types: vec![],
41			}
42		}
43
44		pub fn with_key_types(id: FlowNodeId, key_types: Vec<ValueType>) -> Self {
45			Self {
46				id,
47				layout: RowShape::testing(&[ValueType::Blob, ValueType::Int4]),
48				key_types,
49			}
50		}
51	}
52
53	impl Operator for TestOperator {
54		fn id(&self) -> FlowNodeId {
55			self.id
56		}
57
58		fn capabilities(&self) -> &[OperatorCapability] {
59			OperatorCapability::STANDARD
60		}
61
62		fn apply(&self, _txn: &mut FlowTransaction, _change: Change) -> Result<Change> {
63			todo!()
64		}
65	}
66
67	pub fn test_row() -> EncodedRow {
68		EncodedRow(CowVec::new(vec![1, 2, 3, 4, 5]))
69	}
70
71	pub fn test_key(suffix: &str) -> EncodedKey {
72		EncodedKey::new(format!("test_{}", suffix).into_bytes())
73	}
74
75	pub fn assert_row_eq(actual: &EncodedRow, expected: &EncodedRow) {
76		assert_eq!(actual.to_vec(), expected.to_vec(), "Rows do not match");
77	}
78
79	pub fn create_test_transaction() -> AdminTransaction {
80		let t = TestEngine::new();
81		t.begin_admin(IdentityId::system()).unwrap()
82	}
83}