aboutsummaryrefslogtreecommitdiff
path: root/tests/configuration_toml.ml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/configuration_toml.ml')
-rw-r--r--tests/configuration_toml.ml311
1 files changed, 298 insertions, 13 deletions
diff --git a/tests/configuration_toml.ml b/tests/configuration_toml.ml
index 0a36faf..470af4a 100644
--- a/tests/configuration_toml.ml
+++ b/tests/configuration_toml.ml
@@ -5,12 +5,12 @@ open Test_migration
let nested_group () =
let expected =
Error
- "in field \"sheet\":\n\
- \ in field \"columns\":\n\
- \ while decoding a list:\n\
- \ element 0:\n\
- \ A group function cannot contains another group function, but got\n\
- \ \"max(:A, [counter([:A], [:A])], [])\" \n"
+ {|in field "sheet":
+ in field "columns":
+ while decoding a list:
+ element 0:
+ A group function cannot contains another group function, but got
+ "max(:A, [counter([:A], [:A])], [])"|}
and result =
ConfLoader.load'
{|[source]
@@ -22,14 +22,291 @@ columns = [
"max(:A, [counter([:A], [:A])], [])",
]|}
in
- Alcotest.(check (result Test_migration.syntax string))
+ Alcotest.(check (result Test_migration.syntax Test_migration.trimed_string))
"duplicate" expected result
+(** Load a simple configuration *)
+let load_configuration () =
+ let configuration =
+ ConfLoader.load'
+ {|[source]
+name = ""
+file = ""
+tab = 0
+
+[sheet]
+columns = []|}
+ and expected = Ok ImporterSyntax.dummy_conf in
+ Alcotest.(check (result Test_migration.syntax string))
+ "Simple configuration" expected configuration
+
+let externals () =
+ let configuration =
+ ConfLoader.load'
+ {|[source]
+name = ""
+file = ""
+tab = 0
+
+[externals.other]
+ intern_key = ":A"
+ file = "other.xlsx"
+ extern_key = ":C"
+ allow_missing = false
+
+[sheet]
+columns = []|}
+ and expected =
+ Ok
+ {
+ ImporterSyntax.dummy_conf with
+ externals = [ ConfLoader.external_other ];
+ }
+ in
+ Alcotest.(check (result Test_migration.syntax Test_migration.trimed_string))
+ "Simple external" expected configuration
+
+(** There is an error in this configuration the key [intern_key] is missing in
+ the external *)
+let external_with_missing_key () =
+ let configuration =
+ ConfLoader.load'
+ {|[source]
+name = ""
+file = ""
+
+[externals.other]
+ file = ""
+ extern_key = ""
+
+[sheet]
+columns = []|}
+ and expected =
+ Error
+ {|in field "externals":
+ Failed while decoding key-value pairs:
+ Expected an object with an attribute "intern_key", but got
+ file = ""
+ extern_key = ""|}
+ in
+ Alcotest.(check (result Test_migration.syntax Test_migration.trimed_string))
+ "Missing key" expected configuration
+
+let sub_external () =
+ let configuration =
+ ConfLoader.load'
+ {|[source]
+name = ""
+file = ""
+tab = 0
+
+
+[externals.other-1]
+ intern_key = ":A"
+ file = "other.xlsx"
+ extern_key = ":C"
+ allow_missing = false
+
+[sheet]
+columns = []|}
+ and expected =
+ Ok
+ {
+ ImporterSyntax.dummy_conf with
+ externals =
+ ConfLoader.
+ [
+ {
+ external_other with
+ target = { external_table_other with name = "other-1" };
+ };
+ ];
+ }
+ in
+ Alcotest.(check (result Test_migration.syntax string))
+ "external with path" expected configuration
+
+let sub_external_with_missing_key () =
+ let configuration =
+ ConfLoader.load'
+ {|[source]
+name = ""
+file = ""
+
+[externals.other-1]
+ file = ""
+ extern_key = ""
+
+[sheet]
+columns = []|}
+ and expected =
+ Error
+ {|in field "externals":
+ Failed while decoding key-value pairs:
+ Expected an object with an attribute "intern_key", but got
+ file = ""
+ extern_key = ""|}
+ in
+ Alcotest.(check (result Test_migration.syntax Test_migration.trimed_string))
+ "Missing intern_key" expected configuration
+
+(** The same configuration has external, and sub-element external *)
+let sub_external_mixed () =
+ let configuration =
+ ConfLoader.load'
+ {|[source]
+name = ""
+file = ""
+tab = 0
+
+[externals.other]
+ intern_key = ":A"
+ file = "other.xlsx"
+ extern_key = ":C"
+ allow_missing = false
+
+[externals.other-1]
+ intern_key = ":A"
+ file = "other.xlsx"
+ extern_key = ":C"
+ allow_missing = false
+
+[sheet]
+columns = []|}
+ and expected =
+ Ok
+ {
+ ImporterSyntax.dummy_conf with
+ externals =
+ ConfLoader.
+ [
+ external_other;
+ {
+ external_other with
+ target = { external_table_other with name = "other-1" };
+ };
+ ];
+ }
+ in
+ Alcotest.(check (result Test_migration.syntax string))
+ "external with path" expected configuration
+
+let missing_dataset () =
+ let configuration =
+ ConfLoader.load' {|[source]
+name = ""
+tab = 0
+
+[sheet]
+columns = []|}
+ and expected =
+ Error
+ {|in field "source":
+ I tried the following decoders but they all failed:
+ "file" decoder:
+ Expected an object with an attribute "file", but got name = ""
+ tab = 0
+
+ "dataset" decoder: No dataset declared, but got name = ""
+ tab = 0|}
+ in
+ Alcotest.(check (result Test_migration.syntax Test_migration.trimed_string))
+ "No dataset provided" expected configuration
+
+let empty_dataset () =
+ let configuration =
+ ConfLoader.load'
+ ~dataset:(fun _ -> Otoml.TomlArray [])
+ {|
+
+dataset = "…"
+
+[source]
+name = ""
+
+[sheet]
+columns = []|}
+ and expected =
+ Error
+ {|in field "dataset": Expected an object with an attribute "files", but got []|}
+ in
+ Alcotest.(check (result Test_migration.syntax Test_migration.trimed_string))
+ "Invalid Dataset" expected configuration
+
+let dataset_with_invalid_key () =
+ let configuration =
+ ConfLoader.load'
+ ~dataset:(fun _ ->
+ Otoml.(
+ TomlTable
+ [ ("files", TomlTable [ ("other-1", TomlString "other.xlsx") ]) ]))
+ {|
+
+dataset = "…"
+
+[source]
+name = ""
+
+[sheet]
+columns = []|}
+ and expected =
+ Error
+ {|in field "dataset":
+ in field "files":
+ Failed while decoding key-value pairs:
+ Expected a key without '-', but got "other-1"|}
+ in
+ Alcotest.(check (result Test_migration.syntax Test_migration.trimed_string))
+ "Invalid Dataset: invalid key" expected configuration
+
+let external_dataset () =
+ let configuration =
+ ConfLoader.load'
+ ~dataset:(fun _ ->
+ Otoml.(
+ TomlTable
+ [ ("files", TomlTable [ ("other", TomlString "other.xlsx") ]) ]))
+ {|
+
+dataset = "…"
+
+[source]
+name = ""
+file = ""
+tab = 0
+
+
+[externals.other-1]
+ # The file is not defined here
+ # And in the dataset, there is no "other-1", just "other": the application
+ # should be able to infer the information from "other" and apply it here.
+ intern_key = ":A"
+ extern_key = ":C"
+ allow_missing = false
+
+[sheet]
+columns = []|}
+ and expected =
+ Ok
+ {
+ ImporterSyntax.dummy_conf with
+ externals =
+ ConfLoader.
+ [
+ {
+ external_other with
+ target = { external_table_other with name = "other-1" };
+ };
+ ];
+ }
+ in
+ Alcotest.(check (result Test_migration.syntax string))
+ "Dataset with alias" expected configuration
+
let test_suit =
[
( "parse_extern" >:: fun _ ->
- let toml = Otoml.Parser.from_file "configuration/simple.toml" in
- let toml = ImportConf.t_of_toml toml in
+ let toml = ConfLoader.load_from_file "configuration/simple.toml" in
match toml with
| Error s -> raise (Failure s)
| Ok result ->
@@ -55,8 +332,7 @@ let test_suit =
(Alcotest.list Test_migration.extern_testable)
"" [ expected ] result.externals );
( "parse_columns" >:: fun _ ->
- let toml = Otoml.Parser.from_file "configuration/simple.toml" in
- let toml = ImportConf.t_of_toml toml in
+ let toml = ConfLoader.load_from_file "configuration/simple.toml" in
match toml with
| Error s -> raise (Failure s)
@@ -83,10 +359,19 @@ let test_suit =
(Alcotest.list Test_migration.expression_testable)
"" expected result.columns );
( "parse_csv" >:: fun _ ->
- let toml = Otoml.Parser.from_file "configuration/example_csv.toml" in
- let toml = ImportConf.t_of_toml toml in
+ let toml = ConfLoader.load_from_file "configuration/example_csv.toml" in
ignore toml );
("nested group", `Quick, nested_group);
+ ("Basic configuration", `Quick, load_configuration);
+ ("Configuration with external", `Quick, externals);
+ ("Faulty configuration", `Quick, external_with_missing_key);
+ ("Sub external", `Quick, sub_external);
+ ("Faulty configuration", `Quick, sub_external_with_missing_key);
+ ("Mix in external and sub external", `Quick, sub_external_mixed);
+ ("Missing dataset", `Quick, missing_dataset);
+ ("Empty dataset", `Quick, empty_dataset);
+ ("Dataset with invalid key", `Quick, dataset_with_invalid_key);
+ ("External dataset", `Quick, external_dataset);
]
let tests = "configuration_toml" >::: test_suit