blob: 06163782fa168f4664eef48e1b2d7c7d1580b092 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
|
open OUnit2
open Reference_tree
let get_dir test_ctxt = in_testdata_dir test_ctxt ["validators"]
let raises_validation_error f =
try ignore @@ f (); false
with Validation_error _ -> true
let test_load_valid_definition test_ctxt =
let r = Vytree.make default_data "root" in
let r = load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (Vytree.list_children r) ["system"]
(* Path validation tests *)
let test_validate_path_leaf_valid test_ctxt =
let r = Vytree.make default_data "root" in
let r = load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (validate_path (get_dir test_ctxt) r ["system"; "host-name"; "test"]) (["system"; "host-name"], Some "test")
let test_validate_path_leaf_invalid test_ctxt =
let r = Vytree.make default_data "root" in
let r = load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (raises_validation_error (fun () -> ignore @@ validate_path (get_dir test_ctxt) r ["system"; "host-name"; "1234"])) true
let test_validate_path_leaf_incomplete test_ctxt =
let r = Vytree.make default_data "root" in
let r = load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (raises_validation_error (fun () -> ignore @@ validate_path (get_dir test_ctxt) r ["system"; "host-name"])) true
let test_validate_path_tag_node_complete_valid test_ctxt =
let r = Vytree.make default_data "root" in
let r = load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (validate_path (get_dir test_ctxt) r ["system"; "login"; "user"; "test"; "full-name"; "test user"])
(["system"; "login"; "user"; "test"; "full-name";], Some "test user")
let test_validate_path_tag_node_invalid_name test_ctxt =
let r = Vytree.make default_data "root" in
let r = load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (raises_validation_error (fun () -> ignore @@ validate_path (get_dir test_ctxt) r ["system"; "login"; "user"; "999"; "full-name"; "test user"]))
true
let test_validate_path_tag_node_incomplete test_ctxt =
let r = Vytree.make default_data "root" in
let r = load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (raises_validation_error (fun () -> ignore @@ validate_path (get_dir test_ctxt) r ["system"; "login"; "user"])) true
let suite =
"Util tests" >::: [
"test_load_valid_definition" >:: test_load_valid_definition;
"test_validate_path_leaf_valid" >:: test_validate_path_leaf_valid;
"test_validate_path_leaf_invalid" >:: test_validate_path_leaf_invalid;
"test_validate_path_leaf_incomplete" >:: test_validate_path_leaf_incomplete;
"test_validate_path_tag_node_complete_valid" >:: test_validate_path_tag_node_complete_valid;
"test_validate_path_tag_node_invalid_name" >:: test_validate_path_tag_node_invalid_name;
"test_validate_path_tag_node_incomplete" >:: test_validate_path_tag_node_incomplete;
]
let () =
run_test_tt_main suite
|