summaryrefslogtreecommitdiff
path: root/test/vyconf_config_test.ml
blob: ba77d1c1a01090490e14b98d6c7feceadd463c9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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