@@ -20,21 +20,6 @@ use typed_builder::TypedBuilder;
2020/// security_context_for_rust, and sql_utils_for_rust.
2121/// Other methods throw todo!() errors.
2222///
23- /// # Example
24- ///
25- /// ```
26- /// use cubesqlplanner::test_fixtures::cube_bridge::MockBaseTools;
27- ///
28- /// // Use builder pattern
29- /// let tools = MockBaseTools::builder().build();
30- /// let driver_tools = tools.driver_tools(false).unwrap();
31- /// let sql_templates = tools.sql_templates().unwrap();
32- ///
33- /// // Or with custom components
34- /// let custom_driver = MockDriverTools::with_timezone("Europe/London".to_string());
35- /// let tools = MockBaseTools::builder()
36- /// .driver_tools(custom_driver)
37- /// .build();
3823/// ```
3924#[ derive( Clone , TypedBuilder ) ]
4025pub struct MockBaseTools {
@@ -62,27 +47,22 @@ impl BaseTools for MockBaseTools {
6247 self
6348 }
6449
65- /// Returns driver tools - uses MockDriverTools
6650 fn driver_tools ( & self , _external : bool ) -> Result < Rc < dyn DriverTools > , CubeError > {
6751 Ok ( self . driver_tools . clone ( ) )
6852 }
6953
70- /// Returns SQL templates renderer - uses MockSqlTemplatesRender
7154 fn sql_templates ( & self ) -> Result < Rc < dyn SqlTemplatesRender > , CubeError > {
7255 Ok ( self . sql_templates . clone ( ) )
7356 }
7457
75- /// Returns security context - uses MockSecurityContext
7658 fn security_context_for_rust ( & self ) -> Result < Rc < dyn SecurityContext > , CubeError > {
7759 Ok ( self . security_context . clone ( ) )
7860 }
7961
80- /// Returns SQL utils - uses MockSqlUtils
8162 fn sql_utils_for_rust ( & self ) -> Result < Rc < dyn SqlUtils > , CubeError > {
8263 Ok ( self . sql_utils . clone ( ) )
8364 }
8465
85- /// Generate time series - not implemented in mock
8666 fn generate_time_series (
8767 & self ,
8868 _granularity : String ,
@@ -91,7 +71,6 @@ impl BaseTools for MockBaseTools {
9171 todo ! ( "generate_time_series not implemented in mock" )
9272 }
9373
94- /// Generate custom time series - not implemented in mock
9574 fn generate_custom_time_series (
9675 & self ,
9776 _granularity : String ,
@@ -101,22 +80,18 @@ impl BaseTools for MockBaseTools {
10180 todo ! ( "generate_custom_time_series not implemented in mock" )
10281 }
10382
104- /// Get allocated parameters - not implemented in mock
10583 fn get_allocated_params ( & self ) -> Result < Vec < String > , CubeError > {
10684 todo ! ( "get_allocated_params not implemented in mock" )
10785 }
10886
109- /// Get all cube members - not implemented in mock
11087 fn all_cube_members ( & self , _path : String ) -> Result < Vec < String > , CubeError > {
11188 todo ! ( "all_cube_members not implemented in mock" )
11289 }
11390
114- /// Get interval and minimal time unit - not implemented in mock
11591 fn interval_and_minimal_time_unit ( & self , _interval : String ) -> Result < Vec < String > , CubeError > {
11692 todo ! ( "interval_and_minimal_time_unit not implemented in mock" )
11793 }
11894
119- /// Get pre-aggregation by name - not implemented in mock
12095 fn get_pre_aggregation_by_name (
12196 & self ,
12297 _cube_name : String ,
@@ -125,7 +100,6 @@ impl BaseTools for MockBaseTools {
125100 todo ! ( "get_pre_aggregation_by_name not implemented in mock" )
126101 }
127102
128- /// Get pre-aggregation table name - not implemented in mock
129103 fn pre_aggregation_table_name (
130104 & self ,
131105 _cube_name : String ,
@@ -134,128 +108,10 @@ impl BaseTools for MockBaseTools {
134108 todo ! ( "pre_aggregation_table_name not implemented in mock" )
135109 }
136110
137- /// Get join tree for hints - not implemented in mock
138111 fn join_tree_for_hints (
139112 & self ,
140113 _hints : Vec < JoinHintItem > ,
141114 ) -> Result < Rc < dyn JoinDefinition > , CubeError > {
142115 todo ! ( "join_tree_for_hints not implemented in mock" )
143116 }
144117}
145-
146- #[ cfg( test) ]
147- mod tests {
148- use super :: * ;
149-
150- #[ test]
151- fn test_builder_default ( ) {
152- let tools = MockBaseTools :: builder ( ) . build ( ) ;
153- assert ! ( tools. driver_tools( false ) . is_ok( ) ) ;
154- assert ! ( tools. sql_templates( ) . is_ok( ) ) ;
155- assert ! ( tools. security_context_for_rust( ) . is_ok( ) ) ;
156- assert ! ( tools. sql_utils_for_rust( ) . is_ok( ) ) ;
157- }
158-
159- #[ test]
160- fn test_default_trait ( ) {
161- let tools = MockBaseTools :: default ( ) ;
162- assert ! ( tools. driver_tools( false ) . is_ok( ) ) ;
163- assert ! ( tools. sql_templates( ) . is_ok( ) ) ;
164- assert ! ( tools. security_context_for_rust( ) . is_ok( ) ) ;
165- assert ! ( tools. sql_utils_for_rust( ) . is_ok( ) ) ;
166- }
167-
168- #[ test]
169- fn test_driver_tools ( ) {
170- let tools = MockBaseTools :: builder ( ) . build ( ) ;
171- let driver_tools = tools. driver_tools ( false ) . unwrap ( ) ;
172-
173- // Test that it returns a valid DriverTools implementation
174- let result = driver_tools
175- . time_grouped_column ( "day" . to_string ( ) , "created_at" . to_string ( ) )
176- . unwrap ( ) ;
177- assert_eq ! ( result, "date_trunc('day', created_at)" ) ;
178- }
179-
180- #[ test]
181- fn test_driver_tools_external_flag ( ) {
182- let tools = MockBaseTools :: builder ( ) . build ( ) ;
183-
184- // Both external true and false should work (mock ignores the flag)
185- assert ! ( tools. driver_tools( false ) . is_ok( ) ) ;
186- assert ! ( tools. driver_tools( true ) . is_ok( ) ) ;
187- }
188-
189- #[ test]
190- fn test_sql_templates ( ) {
191- let tools = MockBaseTools :: builder ( ) . build ( ) ;
192- let templates = tools. sql_templates ( ) . unwrap ( ) ;
193-
194- // Test that it returns a valid SqlTemplatesRender implementation
195- assert ! ( templates. contains_template( "filters/equals" ) ) ;
196- assert ! ( templates. contains_template( "functions/SUM" ) ) ;
197- }
198-
199- #[ test]
200- fn test_security_context ( ) {
201- let tools = MockBaseTools :: builder ( ) . build ( ) ;
202- // Just verify it returns without error
203- assert ! ( tools. security_context_for_rust( ) . is_ok( ) ) ;
204- }
205-
206- #[ test]
207- fn test_sql_utils ( ) {
208- let tools = MockBaseTools :: builder ( ) . build ( ) ;
209- // Just verify it returns without error
210- assert ! ( tools. sql_utils_for_rust( ) . is_ok( ) ) ;
211- }
212-
213- #[ test]
214- fn test_builder_with_custom_driver_tools ( ) {
215- let custom_driver = MockDriverTools :: with_timezone ( "Europe/London" . to_string ( ) ) ;
216- let tools = MockBaseTools :: builder ( )
217- . driver_tools ( Rc :: new ( custom_driver) )
218- . build ( ) ;
219-
220- let driver_tools = tools. driver_tools ( false ) . unwrap ( ) ;
221- let result = driver_tools. convert_tz ( "timestamp" . to_string ( ) ) . unwrap ( ) ;
222- assert_eq ! (
223- result,
224- "(timestamp::timestamptz AT TIME ZONE 'Europe/London')"
225- ) ;
226- }
227-
228- #[ test]
229- fn test_builder_with_custom_sql_templates ( ) {
230- let mut custom_templates = std:: collections:: HashMap :: new ( ) ;
231- custom_templates. insert ( "test/template" . to_string ( ) , "TEST {{value}}" . to_string ( ) ) ;
232- let sql_templates = MockSqlTemplatesRender :: try_new ( custom_templates) . unwrap ( ) ;
233-
234- let tools = MockBaseTools :: builder ( )
235- . sql_templates ( Rc :: new ( sql_templates) )
236- . build ( ) ;
237-
238- let templates = tools. sql_templates ( ) . unwrap ( ) ;
239- assert ! ( templates. contains_template( "test/template" ) ) ;
240- }
241-
242- #[ test]
243- fn test_builder_with_all_custom_components ( ) {
244- let driver_tools = MockDriverTools :: with_timezone ( "Asia/Tokyo" . to_string ( ) ) ;
245- let sql_templates = MockSqlTemplatesRender :: default_templates ( ) ;
246- let security_context = MockSecurityContext ;
247- let sql_utils = MockSqlUtils ;
248-
249- let tools = MockBaseTools :: builder ( )
250- . driver_tools ( Rc :: new ( driver_tools) )
251- . sql_templates ( Rc :: new ( sql_templates) )
252- . security_context ( Rc :: new ( security_context) )
253- . sql_utils ( Rc :: new ( sql_utils) )
254- . build ( ) ;
255-
256- assert ! ( tools. driver_tools( false ) . is_ok( ) ) ;
257- assert ! ( tools. sql_templates( ) . is_ok( ) ) ;
258- assert ! ( tools. security_context_for_rust( ) . is_ok( ) ) ;
259- assert ! ( tools. sql_utils_for_rust( ) . is_ok( ) ) ;
260- }
261- }
0 commit comments