Skip to content

Commit 7fc7880

Browse files
authored
test(cubesql): Implement mock TransportService::load for TestConnectionTransport (#8560)
Add TestContext to hold all necessary test harness Intention is to set up mock cube responses during test between text context init and query execution Lift TestConnectionTransport to module level and store it in TestContext Add simple mocks for TransportService::load to TestConnectionTransport, and use it for simple test
1 parent 425d996 commit 7fc7880

File tree

3 files changed

+308
-128
lines changed

3 files changed

+308
-128
lines changed

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ mod tests {
13341334
use chrono::Datelike;
13351335
use cubeclient::models::{
13361336
V1LoadRequestQuery, V1LoadRequestQueryFilterItem, V1LoadRequestQueryTimeDimension,
1337+
V1LoadResponse, V1LoadResult, V1LoadResultAnnotation,
13371338
};
13381339
use pretty_assertions::assert_eq;
13391340
use regex::Regex;
@@ -1357,7 +1358,7 @@ mod tests {
13571358
use crate::compile::test::{
13581359
convert_select_to_query_plan, convert_select_to_query_plan_customized,
13591360
convert_select_to_query_plan_with_config, convert_select_to_query_plan_with_meta,
1360-
execute_queries_with_flags, execute_query, init_testing_logger,
1361+
execute_queries_with_flags, execute_query, init_testing_logger, TestContext,
13611362
};
13621363

13631364
#[tokio::test]
@@ -16451,6 +16452,61 @@ ORDER BY "source"."str0" ASC
1645116452
.contains("EXTRACT"));
1645216453
}
1645316454

16455+
// TODO using this is not correct, but works for now
16456+
fn empty_annotation() -> V1LoadResultAnnotation {
16457+
V1LoadResultAnnotation::new(json!([]), json!([]), json!([]), json!([]))
16458+
}
16459+
16460+
fn simple_load_response(data: Vec<serde_json::Value>) -> V1LoadResponse {
16461+
V1LoadResponse::new(vec![V1LoadResult::new(empty_annotation(), data)])
16462+
}
16463+
16464+
#[tokio::test]
16465+
async fn test_cube_scan_exec() {
16466+
init_testing_logger();
16467+
16468+
let context = TestContext::new(DatabaseProtocol::PostgreSQL).await;
16469+
16470+
// language=PostgreSQL
16471+
let query = r#"
16472+
SELECT dim_str0
16473+
FROM MultiTypeCube
16474+
GROUP BY 1
16475+
"#;
16476+
16477+
let expected_cube_scan = V1LoadRequestQuery {
16478+
measures: Some(vec![]),
16479+
segments: Some(vec![]),
16480+
dimensions: Some(vec!["MultiTypeCube.dim_str0".to_string()]),
16481+
time_dimensions: None,
16482+
order: None,
16483+
limit: None,
16484+
offset: None,
16485+
filters: None,
16486+
ungrouped: None,
16487+
};
16488+
16489+
assert_eq!(
16490+
context
16491+
.convert_sql_to_cube_query(query)
16492+
.await
16493+
.unwrap()
16494+
.as_logical_plan()
16495+
.find_cube_scan()
16496+
.request,
16497+
expected_cube_scan,
16498+
);
16499+
16500+
context
16501+
.add_cube_load_mock(
16502+
expected_cube_scan,
16503+
simple_load_response(vec![json!({"MultiTypeCube.dim_str0": "foo"})]),
16504+
)
16505+
.await;
16506+
16507+
insta::assert_snapshot!(context.execute_query(query).await.unwrap());
16508+
}
16509+
1645416510
#[tokio::test]
1645516511
async fn test_wrapper_tableau_week_number() {
1645616512
if !Rewriter::sql_push_down_enabled() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
source: cubesql/src/compile/mod.rs
3+
expression: context.execute_query(query).await.unwrap()
4+
---
5+
+----------+
6+
| dim_str0 |
7+
+----------+
8+
| foo |
9+
+----------+

0 commit comments

Comments
 (0)