diff options
author | Daniil Baturin <daniil@baturin.org> | 2016-12-15 09:56:07 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2016-12-15 09:56:07 +0600 |
commit | 88cca944fa1788d4f3089c9f93c59666bfcce1fb (patch) | |
tree | 4fb211c72964405f14b25317268ba67c5d995c61 /test | |
parent | 6f95f4191699186a14a3109f08822189d0f8331e (diff) | |
download | vyconf-88cca944fa1788d4f3089c9f93c59666bfcce1fb.tar.gz vyconf-88cca944fa1788d4f3089c9f93c59666bfcce1fb.zip |
T212: use a directory (normally $program_dir/validators) for external validators.
What's bad is that right now way too many things are aware of the nature of external validators,
and the validators dir (formerly validators hashtable) is passed around a lot.
We'll need to think it through.
Diffstat (limited to 'test')
-rwxr-xr-x | test/data/validators/anything | 3 | ||||
-rwxr-xr-x | test/data/validators/nothing | 3 | ||||
-rw-r--r-- | test/reference_tree_test.ml | 18 | ||||
-rw-r--r-- | test/value_checker_test.ml | 25 |
4 files changed, 28 insertions, 21 deletions
diff --git a/test/data/validators/anything b/test/data/validators/anything new file mode 100755 index 0000000..c52d3c2 --- /dev/null +++ b/test/data/validators/anything @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 0 diff --git a/test/data/validators/nothing b/test/data/validators/nothing new file mode 100755 index 0000000..2bb8d86 --- /dev/null +++ b/test/data/validators/nothing @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 1 diff --git a/test/reference_tree_test.ml b/test/reference_tree_test.ml index 1e9a624..0616378 100644 --- a/test/reference_tree_test.ml +++ b/test/reference_tree_test.ml @@ -1,12 +1,10 @@ open OUnit2 open Reference_tree -let validators = Hashtbl.create 256 -let () = Hashtbl.add validators "anything" "true"; - Hashtbl.add validators "nothing" "false" +let get_dir test_ctxt = in_testdata_dir test_ctxt ["validators"] let raises_validation_error f = - try f (); false + try ignore @@ f (); false with Validation_error _ -> true let test_load_valid_definition test_ctxt = @@ -18,34 +16,34 @@ let test_load_valid_definition test_ctxt = 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") + 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 validators r ["system"; "host-name"; "1234"])) true + 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 validators r ["system"; "host-name"])) true + 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 validators r ["system"; "login"; "user"; "test"; "full-name"; "test user"]) + 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 validators r ["system"; "login"; "user"; "999"; "full-name"; "test user"])) + 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 validators r ["system"; "login"; "user"])) true + assert_equal (raises_validation_error (fun () -> ignore @@ validate_path (get_dir test_ctxt) r ["system"; "login"; "user"])) true let suite = diff --git a/test/value_checker_test.ml b/test/value_checker_test.ml index 169ed86..3479150 100644 --- a/test/value_checker_test.ml +++ b/test/value_checker_test.ml @@ -1,46 +1,49 @@ open OUnit2 open Value_checker -let validators = Hashtbl.create 256 -let () = Hashtbl.add validators "anything" "true"; - Hashtbl.add validators "nothing" "false" +let get_dir test_ctxt = in_testdata_dir test_ctxt ["validators"] + +let raises_bad_validator f = + try ignore @@ f (); false + with Bad_validator _ -> true let test_check_regex_valid test_ctxt = let c = Regex "[a-z]+" in let v = "fgsfds" in - assert_equal (validate_value validators c v) true + assert_equal (validate_value (get_dir test_ctxt) c v) true let test_check_regex_invalid test_ctxt = let c = Regex "[a-z]+" in let v = "FGSFDS" in - assert_equal (validate_value validators c v) false + assert_equal (validate_value (get_dir test_ctxt) c v) false let test_check_external_valid test_ctxt = let c = External ("anything", "") in let v = "fgsfds" in - assert_equal (validate_value validators c v) true + assert_equal (validate_value (get_dir test_ctxt) c v) true let test_check_external_invalid test_ctxt = let c = External ("nothing", "") in let v = "fgsfds" in - assert_equal (validate_value validators c v) false + assert_equal (validate_value (get_dir test_ctxt) c v) false let test_check_external_bad_validator test_ctxt = let c = External ("invalid", "") in let v = "fgsfds" in - assert_raises (Bad_validator "invalid") (fun () -> validate_value validators c v) + assert_bool "Invalid validator was executed successfully" + (raises_bad_validator (fun () -> validate_value (get_dir test_ctxt) c v)) let test_validate_any_valid test_ctxt = let cs = [Regex "\\d+"; Regex "[a-z]+"; External ("anything", "")] in - assert_equal (validate_any validators cs "AAAA") true + assert_equal (validate_any (get_dir test_ctxt) cs "AAAA") true let test_validate_any_invalid test_ctxt = let cs = [Regex "\\d+"; Regex "[a-z]+"] in - assert_equal (validate_any validators cs "AAAA") false + assert_equal (validate_any (get_dir test_ctxt) cs "AAAA") false let test_validate_any_no_constraints test_ctxt = let cs = [] in - assert_equal (validate_any validators cs "foo") true + assert_equal (validate_any (get_dir test_ctxt) cs "foo") true let suite = "VyConf value checker tests" >::: [ |