Skip to content

Commit

Permalink
Test all the things, (almost) everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
plcplc committed Jan 16, 2024
1 parent 38b3073 commit 54d0b27
Show file tree
Hide file tree
Showing 48 changed files with 3,742 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"collection": "address_identity_function",
"query": {
"fields": {
"result": {
"type": "column",
"column": "result",
"arguments": {}
}
}
},
"arguments": {
"address": {
"type": "literal",
"value": {
"address_line_1": "Somstreet 159",
"address_line_2": "Second door to the right"
}
}
},
"collection_relationships": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"compositeTypes": {
"person_address": {
"name": "person_address",
"fields": {
"address_line_1": {
"name": "address_line_1",
"type": {
"scalarType": "text"
}
},
"address_line_2": {
"name": "address_line_2",
"type": {
"scalarType": "text"
}
}
}
}
},
"nativeQueries": {
"address_identity_function": {
"sql": "SELECT {{address}} as result",
"columns": {
"result": {
"name": "result",
"type": {
"compositeType": "person_address"
},
"nullable": "nullable",
"description": null
}
},
"arguments": {
"address": {
"name": "address",
"type": {
"compositeType": "person_address"
},
"nullable": "nullable",
"description": null
}
},
"description": "A native query used to test support for composite types"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"collection": "address_identity_function",
"query": {
"fields": {
"result": {
"type": "column",
"column": "result",
"arguments": {}
}
}
},
"arguments": {
"address": {
"type": "variable",
"name": "variable_address"
}
},
"collection_relationships": {},
"variables": [
{
"variable_address": {
"address_line_1": "Somstreet 159",
"address_line_2": "Second door to the right"
}
},
{
"variable_address": {
"address_line_1": "Somstreet 159",
"address_line_2": "Second door to the right"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"compositeTypes": {
"person_address": {
"name": "person_address",
"fields": {
"address_line_1": {
"name": "address_line_1",
"type": {
"scalarType": "text"
}
},
"address_line_2": {
"name": "address_line_2",
"type": {
"scalarType": "text"
}
}
}
}
},
"nativeQueries": {
"address_identity_function": {
"sql": "SELECT {{address}} as result",
"columns": {
"result": {
"name": "result",
"type": {
"compositeType": "person_address"
},
"nullable": "nullable",
"description": null
}
},
"arguments": {
"address": {
"name": "address",
"type": {
"compositeType": "person_address"
},
"nullable": "nullable",
"description": null
}
},
"description": "A native query used to test support for composite types"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: crates/query-engine/translation/tests/tests.rs
expression: result
---
WITH "%1_NATIVE_QUERY_address_identity_function" AS (
SELECT
jsonb_populate_record(cast(null as person_address), $1) as result
)
SELECT
coalesce(json_agg(row_to_json("%2_universe")), '[]') AS "universe"
FROM
(
SELECT
*
FROM
(
SELECT
coalesce(json_agg(row_to_json("%3_rows")), '[]') AS "rows"
FROM
(
SELECT
"%0_address_identity_function"."result" AS "result"
FROM
"%1_NATIVE_QUERY_address_identity_function" AS "%0_address_identity_function"
) AS "%3_rows"
) AS "%3_rows"
) AS "%2_universe"

[(1, Value(Object {"address_line_1": String("Somstreet 159"), "address_line_2": String("Second door to the right")}))]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
source: crates/query-engine/translation/tests/tests.rs
expression: result
---
SELECT
coalesce(json_agg("%6_universe_agg"."universe"), '[]') AS "universe"
FROM
(
SELECT
row_to_json("%3_universe") AS "universe"
FROM
jsonb_to_recordset($1) AS "%0_%variables_table"("%variable_order" int, "%variables" jsonb)
CROSS JOIN LATERAL (
WITH "%2_NATIVE_QUERY_address_identity_function" AS (
SELECT
jsonb_populate_record(
cast(null as person_address),
("%0_%variables_table"."%variables" -> $2)
) as result
)
SELECT
*
FROM
(
SELECT
coalesce(json_agg(row_to_json("%4_rows")), '[]') AS "rows"
FROM
(
SELECT
"%1_address_identity_function"."result" AS "result"
FROM
"%2_NATIVE_QUERY_address_identity_function" AS "%1_address_identity_function"
) AS "%4_rows"
) AS "%4_rows"
) AS "%3_universe"
ORDER BY
"%0_%variables_table"."%variable_order" ASC
) AS "%6_universe_agg"

[(1, Variable("%VARIABLES_OBJECT_PLACEHOLDER")), (2, String("variable_address"))]
20 changes: 16 additions & 4 deletions crates/query-engine/translation/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ fn select_array_column() {
}

#[test]
fn select_composite_column() {
let result = common::test_translation("select_composite_column").unwrap();
fn select_composite_column_simple() {
let result = common::test_translation("select_composite_column_simple").unwrap();
insta::assert_snapshot!(result);
}

#[test]
fn select_composite_variable() {
let result = common::test_translation("select_composite_variable").unwrap();
fn select_composite_column_complex() {
let result = common::test_translation("select_composite_column_complex").unwrap();
insta::assert_snapshot!(result);
}

#[test]
fn select_composite_variable_simple() {
let result = common::test_translation("select_composite_variable_simple").unwrap();
insta::assert_snapshot!(result);
}

#[test]
fn select_composite_variable_complex() {
let result = common::test_translation("select_composite_variable_complex").unwrap();
insta::assert_snapshot!(result);
}

Expand Down
28 changes: 28 additions & 0 deletions crates/tests/databases-tests/src/aurora/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ mod basic {
let result = run_query(create_router().await, "select_int_and_string").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
#[ignore = "Pending update of aurora test database"]
async fn select_composite_column_simple() {
let result = run_query(create_router().await, "select_composite_column_simple").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
#[ignore = "Pending update of aurora test database"]
async fn select_composite_column_complex() {
let result = run_query(create_router().await, "select_composite_column_complex").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
#[ignore = "Pending update of aurora test database"]
async fn select_composite_variable_simple() {
let result = run_query(create_router().await, "select_composite_variable_simple").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
#[ignore = "Pending update of aurora test database"]
async fn select_composite_variable_complex() {
let result = run_query(create_router().await, "select_composite_variable_complex").await;
insta::assert_json_snapshot!(result);
}
}

#[cfg(test)]
Expand Down
20 changes: 16 additions & 4 deletions crates/tests/databases-tests/src/citus/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@ mod basic {
}

#[tokio::test]
async fn select_composite_column() {
let result = run_query(create_router().await, "select_composite_column").await;
async fn select_composite_column_simple() {
let result = run_query(create_router().await, "select_composite_column_simple").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_composite_variable() {
let result = run_query(create_router().await, "select_composite_variable").await;
async fn select_composite_column_complex() {
let result = run_query(create_router().await, "select_composite_column_complex").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_composite_variable_simple() {
let result = run_query(create_router().await, "select_composite_variable_simple").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_composite_variable_complex() {
let result = run_query(create_router().await, "select_composite_variable_complex").await;
insta::assert_json_snapshot!(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: crates/tests/databases-tests/src/citus/query_tests.rs
expression: result
---
[
{
"rows": [
{
"result": {
"address_line_1": "Somstreet 159",
"address_line_2": "Second door to the right"
}
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
source: crates/tests/databases-tests/src/citus/query_tests.rs
expression: result
---
[
{
"rows": [
{
"result": {
"address_line_1": "Somstreet 159",
"address_line_2": "Second door to the right"
}
}
]
},
{
"rows": [
{
"result": {
"address_line_1": "Somstreet 159",
"address_line_2": "Second door to the right"
}
}
]
}
]
Loading

0 comments on commit 54d0b27

Please sign in to comment.