summaryrefslogtreecommitdiff
path: root/test/vyconf_config_test.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/vyconf_config_test.ml')
-rw-r--r--test/vyconf_config_test.ml49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/vyconf_config_test.ml b/test/vyconf_config_test.ml
new file mode 100644
index 0000000..ba77d1c
--- /dev/null
+++ b/test/vyconf_config_test.ml
@@ -0,0 +1,49 @@
+open OUnit2
+open Vyconf_config
+
+let try_load file =
+ let conf = load file in
+ match conf with
+ | Ok _ -> ()
+ | Error msg -> assert_failure msg
+
+let try_load_fail file err =
+ let conf = load file in
+ match conf with
+ | Ok _ -> assert_failure err
+ | Error msg -> ()
+
+
+let test_load_nonexistent_file test_ctxt =
+ (* Please don't create this file there! *)
+ let file = in_testdata_dir test_ctxt ["vyconfd_config"; "vyconfd.conf.nonexistent"] in
+ try_load_fail file (Printf.sprintf "Nonexistent file %s was successfully loaded" file)
+
+let test_load_malformed_file test_ctxt =
+ let file = in_testdata_dir test_ctxt ["vyconfd_config"; "vyconfd.conf.malformed"] in
+ try_load_fail file (Printf.sprintf "Malformed file %s was successfully loaded" file)
+
+let test_load_incomplete_file test_ctxt =
+ let file = in_testdata_dir test_ctxt ["vyconfd_config"; "vyconfd.conf.incomplete"] in
+ try_load_fail file (Printf.sprintf "File %s was successfully loaded despite missing fields" file)
+
+let test_load_mandatory_only test_ctxt =
+ let file = in_testdata_dir test_ctxt ["vyconfd_config"; "vyconfd.conf.mandatoryonly"] in
+ try_load file
+
+let test_load_all_fields test_ctxt =
+ let file = in_testdata_dir test_ctxt ["vyconfd_config"; "vyconfd.conf.complete"] in
+ try_load file
+
+let suite =
+ "VyConf daemon config loader tests" >::: [
+ "test_load_nonexistent_file" >:: test_load_nonexistent_file;
+ "test_load_malformed_file" >:: test_load_malformed_file;
+ "test_load_incomplete_file" >:: test_load_incomplete_file;
+ "test_load_mandatory_only" >:: test_load_mandatory_only;
+ "test_load_all_fields" >:: test_load_all_fields;
+
+ ]
+
+let () =
+ run_test_tt_main suite