@@ -2,36 +2,58 @@ use std::fs;
2
2
3
3
use query_engine_sql:: sql;
4
4
use query_engine_translation:: translation;
5
+ use std:: path:: PathBuf ;
5
6
6
7
/// Run a query against the server, get the result, and compare against the snapshot.
7
- pub fn test_translation ( testname : & str ) -> anyhow:: Result < String > {
8
- let tables = serde_json:: from_str (
9
- fs:: read_to_string ( format ! ( "tests/goldenfiles/{}/tables.json" , testname) )
10
- . unwrap ( )
11
- . as_str ( ) ,
12
- )
13
- . unwrap ( ) ;
14
- let request = serde_json:: from_str (
15
- fs:: read_to_string ( format ! ( "tests/goldenfiles/{}/request.json" , testname) )
16
- . unwrap ( )
17
- . as_str ( ) ,
18
- )
19
- . unwrap ( ) ;
20
-
21
- let plan = translation:: query:: translate ( & tables, request) ?;
8
+ pub async fn test_translation ( testname : & str ) -> anyhow:: Result < String > {
9
+ // let tables = serde_json::from_str(
10
+ // fs::read_to_string(format!("tests/goldenfiles/{}/tables.json", testname))
11
+ // .unwrap()
12
+ // .as_str(),
13
+ // )
14
+ // .unwrap();
15
+
16
+ let directory = PathBuf :: from ( "tests/goldenfiles" ) . join ( testname) ;
17
+
18
+ let parsed_configuration = ndc_bigquery_configuration:: parse_configuration ( & directory) . await ?;
19
+ let configuration = ndc_bigquery_configuration:: make_runtime_configuration (
20
+ parsed_configuration,
21
+ ndc_bigquery_configuration:: environment:: FixedEnvironment :: from ( [
22
+ (
23
+ "HASURA_BIGQUERY_SERVICE_KEY" . into ( ) ,
24
+ "the translation tests do not rely on a database connection" . into ( ) ,
25
+ ) ,
26
+ (
27
+ "HASURA_BIGQUERY_PROJECT_ID" . into ( ) ,
28
+ "the translation tests do not rely on a database connection" . into ( ) ,
29
+ ) ,
30
+ (
31
+ "HASURA_BIGQUERY_DATASET_ID" . into ( ) ,
32
+ "the translation tests do not rely on a database connection" . into ( ) ,
33
+ ) ,
34
+ ] ) ,
35
+ ) ?;
36
+ let metadata = configuration. metadata ;
37
+
38
+ let request =
39
+ serde_json:: from_str ( & fs:: read_to_string ( directory. join ( "request.json" ) ) . unwrap ( ) ) . unwrap ( ) ;
40
+
41
+ let plan = translation:: query:: translate ( & metadata, request) ?;
22
42
let query = plan. query . query_sql ( ) ;
23
43
let params: Vec < ( usize , & sql:: string:: Param ) > = query
24
44
. params
25
45
. iter ( )
26
46
. enumerate ( )
27
47
. map ( |( i, p) | ( i + 1 , p) )
28
48
. collect ( ) ;
49
+ dbg ! ( & query) ;
29
50
30
51
let pretty = sqlformat:: format (
31
52
& query. sql ,
32
53
& sqlformat:: QueryParams :: None ,
33
54
sqlformat:: FormatOptions :: default ( ) ,
34
55
) ;
56
+ dbg ! ( & pretty) ;
35
57
36
58
Ok ( format ! ( "{}\n \n {:?}" , pretty, params) )
37
59
}
0 commit comments