diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-04-26 15:03:19 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-04-26 15:03:19 +0600 |
commit | 727deb901e3090653644a135c238c2f2878a4d8e (patch) | |
tree | 6275e0bdabdd3ba7d045d8f2dbf7d41aa275c68e /test/reference_tree_test.ml | |
parent | 35bbd44f54b2738027869d67c99f55c742945a5e (diff) | |
download | vyconf-727deb901e3090653644a135c238c2f2878a4d8e.tar.gz vyconf-727deb901e3090653644a135c238c2f2878a4d8e.zip |
Add path validation functionality.
Diffstat (limited to 'test/reference_tree_test.ml')
-rw-r--r-- | test/reference_tree_test.ml | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/test/reference_tree_test.ml b/test/reference_tree_test.ml index 52e5a8d..8c969ab 100644 --- a/test/reference_tree_test.ml +++ b/test/reference_tree_test.ml @@ -1,14 +1,62 @@ open OUnit2 open Reference_tree +let validators = Hashtbl.create 256 +let () = Hashtbl.add validators "anything" "true"; + Hashtbl.add validators "nothing" "false" + +let raises_validation_error f = + try 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) ["login"] + 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 validators 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 () -> validate_path validators 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 () -> validate_path validators 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 validators 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 () -> validate_path validators 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 () -> validate_path validators 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 () = |