summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_oasis14
-rw-r--r--test/data/vyconfd_config/vyconfd.conf.complete17
-rw-r--r--test/data/vyconfd_config/vyconfd.conf.incomplete13
-rw-r--r--test/data/vyconfd_config/vyconfd.conf.malformed7
-rw-r--r--test/data/vyconfd_config/vyconfd.conf.mandatoryonly11
-rw-r--r--test/vyconf_config_test.ml49
6 files changed, 111 insertions, 0 deletions
diff --git a/_oasis b/_oasis
index 4dbbb3e..48bd8ca 100644
--- a/_oasis
+++ b/_oasis
@@ -115,6 +115,14 @@ Executable "util_test"
Install: false
BuildDepends: oUnit, vyconf, xml-light
+Executable "vyconf_config_test"
+ Path: test
+ MainIs: vyconf_config_test.ml
+ Build$: flag(tests)
+ CompiledObject: best
+ Install: false
+ BuildDepends: oUnit, toml, ppx_deriving.runtime, vyconf
+
Executable "vytree_load_test"
Path: test
MainIs: vytree_load_test.ml
@@ -153,6 +161,12 @@ Test "value_checker_test"
Command: $value_checker_test
WorkingDirectory: test
+Test "vyconf_config_test"
+ Run$: flag(tests)
+ TestTools: vyconf_config_test
+ Command: $vyconf_config_test
+ WorkingDirectory: test
+
Test "util_test"
Run$: flag(tests)
TestTools: util_test
diff --git a/test/data/vyconfd_config/vyconfd.conf.complete b/test/data/vyconfd_config/vyconfd.conf.complete
new file mode 100644
index 0000000..85a4523
--- /dev/null
+++ b/test/data/vyconfd_config/vyconfd.conf.complete
@@ -0,0 +1,17 @@
+[appliance]
+
+name = "Test Appliance"
+
+data_dir = "/usr/share/testappliance"
+program_dir = "/usr/libexec/testappliance"
+config_dir = "/etc/testappliance"
+
+# paths relative to config_dir
+primary_config = "config.boot"
+fallback_config = "config.failsafe"
+
+[vyconf]
+
+socket = "/var/run/vyconfd.sock"
+pid_file = "/var/run/vyconfd.pid"
+log_file = "/var/log/vyconfd.log"
diff --git a/test/data/vyconfd_config/vyconfd.conf.incomplete b/test/data/vyconfd_config/vyconfd.conf.incomplete
new file mode 100644
index 0000000..7ce5c3b
--- /dev/null
+++ b/test/data/vyconfd_config/vyconfd.conf.incomplete
@@ -0,0 +1,13 @@
+[appliance]
+
+name = "Test Appliance"
+
+primary_config = "config.boot"
+fallback_config = "config.failsafe"
+
+[vyconf]
+
+socket = "/var/run/vyconfd.sock"
+pid_file = "/var/run/vyconfd.pid"
+log_file = "/var/log/vyconfd.log"
+
diff --git a/test/data/vyconfd_config/vyconfd.conf.malformed b/test/data/vyconfd_config/vyconfd.conf.malformed
new file mode 100644
index 0000000..c5d6f3d
--- /dev/null
+++ b/test/data/vyconfd_config/vyconfd.conf.malformed
@@ -0,0 +1,7 @@
+# A config with syntax errors
+
+[appliance
+
+name = "Bad Appliance
+
+
diff --git a/test/data/vyconfd_config/vyconfd.conf.mandatoryonly b/test/data/vyconfd_config/vyconfd.conf.mandatoryonly
new file mode 100644
index 0000000..00166fb
--- /dev/null
+++ b/test/data/vyconfd_config/vyconfd.conf.mandatoryonly
@@ -0,0 +1,11 @@
+[appliance]
+
+name = "Test Appliance"
+
+data_dir = "/usr/share/testappliance"
+program_dir = "/usr/libexec/testappliance"
+config_dir = "/etc/testappliance"
+
+# paths relative to config_dir
+primary_config = "config.boot"
+fallback_config = "config.failsafe"
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