aboutsummaryrefslogtreecommitdiff
path: root/tests/analyser_query_test.ml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/analyser_query_test.ml')
-rw-r--r--tests/analyser_query_test.ml78
1 files changed, 20 insertions, 58 deletions
diff --git a/tests/analyser_query_test.ml b/tests/analyser_query_test.ml
index 5d7366b..0e23f11 100644
--- a/tests/analyser_query_test.ml
+++ b/tests/analyser_query_test.ml
@@ -1,60 +1,22 @@
-open OUnit2
open StdLabels
module A = ImportAnalyser.Dependency
module Q = ImportAnalyser.Query
module C = ImportConf
module Syntax = ImportConf.Syntax
module Expr = Expression_builder
-
-let show_source (source : ImportDataTypes.Table.t) =
- Printf.sprintf "%s:%d" source.ImportDataTypes.Table.file source.tab
-
-let show_sources sources =
- let b = Buffer.create 16 in
- Buffer.add_string b "[";
- List.iter sources ~f:(fun source ->
- Buffer.add_string b (show_source source);
- Buffer.add_string b ",");
-
- let len = Buffer.length b in
- if len > 1 then Buffer.truncate b (len - 1);
- Buffer.add_string b "]";
-
- Buffer.contents b
+open Test_migration
(** This is sample configuration used in the tests *)
let conf =
Syntax.
{
- version = 1;
- locale = None;
- source = { file = "source.xlsx"; tab = 1; name = "source" };
- externals =
- [
- {
- intern_key = Path { alias = None; column = 1 };
- target = { file = "other.xlsx"; tab = 1; name = "other" };
- extern_key = Path 3;
- allow_missing = false;
- match_rule = None;
- };
- {
- intern_key = Path { alias = Some "other"; column = 1 };
- target = { file = "last.xlsx"; tab = 1; name = "last_file" };
- extern_key = Path 3;
- allow_missing = true;
- match_rule = None;
- };
- ];
+ ConfLoader.conf with
columns =
[
Concat [ Path { alias = None; column = 1 }; Literal "_"; Empty ];
Path { alias = None; column = 2 };
Path { alias = Some "last_file"; column = 5 };
];
- filters = [];
- sort = [];
- uniq = [];
}
let create_table =
@@ -63,7 +25,7 @@ let create_table =
let query = Q.create_table (List.hd out) in
- assert_equal ~printer:Fun.id
+ Alcotest.check Alcotest.string ""
"CREATE TABLE 'last' (id INTEGER PRIMARY KEY,'key_last_file','col_5')" query
let select =
@@ -78,7 +40,7 @@ LEFT JOIN 'other' AS 'other' ON rtrim(upper('source'.col_1)) = 'other'.'key_othe
LEFT JOIN 'last' AS 'last_file' ON rtrim(upper('other'.col_1)) = 'last_file'.'key_last_file'|}
in
- assert_equal ~printer:Fun.id expected_query query.q
+ Alcotest.check Alcotest.string "" expected_query query.q
let check_externals =
"Check external" >:: fun _ ->
@@ -92,7 +54,7 @@ let check_externals =
IS NOT NULL AND 'source'.col_1 <> ''"
in
- assert_equal ~printer:Fun.id expected_query query.q
+ Alcotest.check Alcotest.string "" expected_query query.q
let previous =
"Test window previous" >:: fun _ ->
@@ -117,13 +79,13 @@ let previous =
}
in
- let res, _ = ImportAnalyser.Query.select conf in
- let query =
+ let query, _ = ImportAnalyser.Query.select conf in
+ let expected_query =
"SELECT LAG('previous'.col_5) OVER (PARTITION BY 'previous'.col_1 ORDER BY \
'previous'.col_3) AS result_0\n\
FROM 'source' AS 'previous'"
in
- assert_equal ~printer:Fun.id query res.q
+ Alcotest.check Alcotest.string "" expected_query query.q
let sum =
"Test window sum" >:: fun _ ->
@@ -148,13 +110,13 @@ let sum =
}
in
- let res, _ = ImportAnalyser.Query.select conf in
- let query =
+ let query, _ = ImportAnalyser.Query.select conf in
+ let expected_query =
"SELECT SUM('previous'.col_5) OVER (PARTITION BY 'previous'.col_1) AS \
result_0\n\
FROM 'source' AS 'previous'"
in
- assert_equal ~printer:Fun.id query res.q
+ Alcotest.check Alcotest.string "" expected_query query.q
let sum_total =
"Test sum over the whole range" >:: fun _ ->
@@ -173,11 +135,11 @@ let sum_total =
}
in
- let res, _ = ImportAnalyser.Query.select conf in
- let query =
+ let query, _ = ImportAnalyser.Query.select conf in
+ let expected_query =
"SELECT SUM('previous'.col_5) AS result_0\nFROM 'source' AS 'previous'"
in
- assert_equal ~printer:Fun.id query res.q
+ Alcotest.check Alcotest.string "" expected_query query.q
let sum_unfiltered =
"Test sum over the whole range" >:: fun _ ->
@@ -202,11 +164,11 @@ let sum_unfiltered =
}
in
- let res, _ = ImportAnalyser.Query.select conf in
- let query =
+ let query, _ = ImportAnalyser.Query.select conf in
+ let expected_query =
"SELECT SUM('previous'.col_5) AS result_0\nFROM 'source' AS 'previous'"
in
- assert_equal ~printer:Fun.id query res.q
+ Alcotest.check Alcotest.string "" expected_query query.q
let prepare_insert =
"Test prepare_insert" >:: fun _ ->
@@ -225,7 +187,7 @@ let prepare_insert =
let expected = "rtrim(upper(COALESCE(:col_1,'') || '_' || ''))" in
- assert_equal ~printer:Fun.id expected contents
+ Alcotest.check Alcotest.string "" expected contents
(** Test a request with a group in a filter.
@@ -256,7 +218,7 @@ INNER JOIN 'cte' ON cte.id = source.id
WHERE (cte.group0)|}
in
- assert_equal ~printer:(fun s -> Printf.sprintf "\n%s" s) expected contents.q
+ Alcotest.check Alcotest.string "" expected contents.q
(** Test a request with a group in a filter.
@@ -290,7 +252,7 @@ WHERE COALESCE('source'.col_3,0)=0
AND (cte.group0)|}
in
- assert_equal ~printer:(fun s -> Printf.sprintf "\n%s" s) expected contents.q
+ Alcotest.check Alcotest.string "" expected contents.q
let test_suit =
[