summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2024-11-07 18:02:08 +0000
committerGitHub <noreply@github.com>2024-11-07 18:02:08 +0000
commit196fdd7fdf6dcf751b7364c59e34278bfd0193e3 (patch)
treecfeff0991481c8281e24cf1698b20a76854059a4 /test
parentdd9271b4304c6b1a5a2576821d1b2b8fd3aa6bf5 (diff)
parent9b90d3cc4da72c13ef4270150e4b547ff03fc813 (diff)
downloadvyconf-master.tar.gz
vyconf-master.zip
Merge pull request #11 from jestabro/vyconf-minimalHEADmaster
T6718: use the vyconf daemon for validation of set commands
Diffstat (limited to 'test')
-rw-r--r--test/config_tree_test.ml75
-rw-r--r--test/data/interface_definition_sample.xml1
-rw-r--r--test/dune3
-rw-r--r--test/reference_tree_test.ml199
-rw-r--r--test/session_test.ml8
-rw-r--r--test/util_test.ml12
-rw-r--r--test/value_checker_test.ml37
-rw-r--r--test/vyconf_config_test.ml5
-rw-r--r--test/vylist_test.ml4
-rw-r--r--test/vytree_load_test.ml17
-rw-r--r--test/vytree_test.ml8
11 files changed, 189 insertions, 180 deletions
diff --git a/test/config_tree_test.ml b/test/config_tree_test.ml
index 442c4c8..a9202f2 100644
--- a/test/config_tree_test.ml
+++ b/test/config_tree_test.ml
@@ -1,7 +1,10 @@
+[@@@ocaml.warning "-27"]
+
open OUnit2
-module VT = Vytree
-module CT = Config_tree
+module VT = Vyos1x.Vytree
+module CT = Vyos1x.Config_tree
+module RT = Vyos1x.Reference_tree
(* Setting a value of a node that doesn't exist should create the node *)
let test_set_create_node test_ctxt =
@@ -69,6 +72,8 @@ let test_set_comment test_ctxt =
let node = CT.set_comment node path (Some "comment") in
assert_equal (CT.get_comment node path) (Some "comment")
+(**** Properties ephemeral and inactive: not yet implemented *)
+(*
(* Creating a node without a value should default inactive and ephemeral to false *)
let test_valueless_node_inactive_ephemeral test_ctxt =
let path = ["foo"; "bar"] in
@@ -77,7 +82,7 @@ let test_valueless_node_inactive_ephemeral test_ctxt =
assert_equal ((not (CT.is_inactive node path)) && (not (CT.is_ephemeral node path))) true
(* Setting a node inactive should work *)
-let test_set_inactive test_ctxt =
+let test_set_inactive test_ctxt =
let path = ["foo"; "bar"] in
let node = CT.make "root" in
let node = CT.set node path None CT.AddValue in
@@ -85,12 +90,14 @@ let test_set_inactive test_ctxt =
assert_equal (CT.is_inactive node path) true
(* Setting a node ephemeral should work *)
-let test_set_ephemeral test_ctxt =
+let test_set_ephemeral test_ctxt =
let path = ["foo"; "bar"] in
let node = CT.make "root" in
let node = CT.set node path None CT.AddValue in
let node = CT.set_ephemeral node path (true) in
assert_equal (CT.is_ephemeral node path) true
+*)
+
(*** Refactoring test setup *)
let set ?(how=CT.AddValue) path value node = CT.set node path value how
@@ -107,8 +114,8 @@ let toggle_in_config_tree ~how ?(path=[]) ?(value=false) =
let load_reftree test_ctxt =
let file_name = "interface_definition_sample.xml" in
- let r = Vytree.make Reference_tree.default_data "root" in
- Reference_tree.load_from_xml r (in_testdata_dir test_ctxt [file_name])
+ let r = VT.make RT.default_data "root" in
+ RT.load_from_xml r (in_testdata_dir test_ctxt [file_name])
let foobar = ["foo"; "bar"]
@@ -116,41 +123,15 @@ let foobar = ["foo"; "bar"]
(**** Standalone rendering *)
let test_render_nested_empty_with_comment test_ctxt =
- let rendered = CT.render @@
+ let rendered = CT.render_config @@
set_in_config_tree
~how:CT.set_comment ~value:"comment"
~path:foobar
in
- assert_equal rendered
-"root {
- foo {
- /*comment*/
- bar { }
- }
-}"
-
-let test_render_ephemeral_hidden teset_ctxt =
- let rendered = CT.render @@
- toggle_in_config_tree
- ~how:CT.set_ephemeral ~value:true
- ~path:foobar
- in
- assert_equal rendered
-"root {
- foo { }
-}"
-
-let test_render_ephemeral_shown teset_ctxt =
- let rendered = CT.render ~showephemeral:true @@
- toggle_in_config_tree
- ~how:CT.set_ephemeral ~value:true
- ~path:foobar
- in
- assert_equal rendered
-"root {
- foo {
- #EPHEMERAL bar { }
- }
+ assert_equal (String.trim rendered)
+"foo {
+ /* comment */
+ bar
}"
let test_render_at_level test_ctxt =
@@ -160,7 +141,7 @@ let test_render_at_level test_ctxt =
let rendered = CT.render_at_level node ["foo"] in
assert_equal (String.trim rendered)
"bar {
- baz quux;
+ baz \"quux\"
}"
let test_render_at_level_top test_ctxt =
@@ -172,19 +153,20 @@ let test_render_at_level_top test_ctxt =
let rendered = CT.render_at_level node [] in
assert_equal (String.trim rendered)
"baz {
- quux xyzzy;
+ quux \"xyzzy\"
}
foo {
- bar quuux;
+ bar \"quuux\"
}"
-(**** Reftree-based rendering *)
+(**** Reftree-based rendering: not yet implemented *)
+(*
let test_render_rt_tag_node test_ctxt =
let reftree = load_reftree test_ctxt in
let path = ["system"; "login"; "user"; "full-name"] in
let node = CT.make "root" in
let node = CT.set node path (Some "name here") CT.AddValue in
- let rendered_curly_config = CT.render ~reftree:(Some reftree) node in
+ let rendered_curly_config = CT.render_config ~reftree:(Some reftree) node in
let desired_rendered_form =
"root {
system {
@@ -212,7 +194,7 @@ let test_render_rt_unspecified_node test_ctxt =
}"
in
assert_equal rendered_curly_config desired_rendered_form
-
+*)
let suite =
"VyConf config tree tests" >::: [
"test_set_create_node" >:: test_set_create_node;
@@ -223,16 +205,9 @@ let suite =
"test_delete_last_value" >:: test_delete_last_value;
"test_delete_subtree" >:: test_delete_subtree;
"test_set_comment" >:: test_set_comment;
- "test_valueless_node_inactive_ephemeral" >:: test_valueless_node_inactive_ephemeral;
- "test_set_inactive" >:: test_set_inactive;
- "test_set_ephemeral" >:: test_set_ephemeral;
"test_render_nested_empty_with_comment" >:: test_render_nested_empty_with_comment;
- "test_render_ephemeral_hidden " >:: test_render_ephemeral_hidden;
- "test_render_ephemeral_shown" >:: test_render_ephemeral_shown;
"test_render_at_level" >:: test_render_at_level;
"test_render_at_level_top" >:: test_render_at_level_top;
- "test_render_rt_tag_node" >:: test_render_rt_tag_node;
- "test_render_rt_unspecified_node" >:: test_render_rt_unspecified_node
]
let () =
diff --git a/test/data/interface_definition_sample.xml b/test/data/interface_definition_sample.xml
index c5458ff..964528d 100644
--- a/test/data/interface_definition_sample.xml
+++ b/test/data/interface_definition_sample.xml
@@ -6,7 +6,6 @@
<children>
<tagNode name="user">
<properties>
- <keepChildOrder/>
<help>User name</help>
<constraint>
<regex>[a-zA-Z][a-zA-Z0-9\-]+</regex>
diff --git a/test/dune b/test/dune
new file mode 100644
index 0000000..93641a0
--- /dev/null
+++ b/test/dune
@@ -0,0 +1,3 @@
+(tests
+ (names config_tree_test reference_tree_test session_test util_test value_checker_test vyconf_config_test vylist_test vytree_load_test vytree_test)
+ (libraries ounit2 vyos1x-config vyconfd_config))
diff --git a/test/reference_tree_test.ml b/test/reference_tree_test.ml
index 1186130..561eb8e 100644
--- a/test/reference_tree_test.ml
+++ b/test/reference_tree_test.ml
@@ -1,5 +1,8 @@
open OUnit2
-open Reference_tree
+
+module RT = Vyos1x.Reference_tree
+module VT = Vyos1x.Vytree
+module VL = Vyos1x.Vylist
let get_dir test_ctxt = in_testdata_dir test_ctxt ["validators"]
@@ -9,162 +12,176 @@ let ok_or_failure result = match result with
let raises_validation_error f =
try ignore @@ f (); false
- with Validation_error _ -> true
+ with RT.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 (Vylist.in_list (Vytree.list_children r) "system") true;
- assert_equal (Vylist.in_list (Vytree.list_children r) "interfaces") true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (VL.in_list (VT.list_children r) "system") true;
+ assert_equal (VL.in_list (VT.list_children r) "interfaces") true
(* 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 r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ let test p =
+ let _ = RT.validate_path (get_dir test_ctxt) r p in
+ RT.split_path r p
+ in
+ assert_equal (test ["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 r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (raises_validation_error (fun () -> ignore @@ RT.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 r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (raises_validation_error (fun () -> ignore @@ RT.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"])
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ let test p =
+ let _ = RT.validate_path (get_dir test_ctxt) r p in
+ RT.split_path r p
+ in
+ assert_equal (test ["system"; "login"; "user"; "test"; "full-name"; "test user"])
(["system"; "login"; "user"; "test"; "full-name";], Some "test user")
let test_validate_path_tag_node_illegal_characters 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
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
(* the space in "eth 0" is on purpose *)
- assert_equal (raises_validation_error (fun () -> ignore @@ validate_path (get_dir test_ctxt) r ["interfaces"; "ethernet"; "eth 0"; "disable"])) true
+ assert_equal (raises_validation_error (fun () -> ignore @@ RT.validate_path (get_dir test_ctxt) r ["interfaces"; "ethernet"; "eth 0"; "disable"])) true
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"]))
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (raises_validation_error (fun () -> ignore @@ RT.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 r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (raises_validation_error (fun () -> ignore @@ RT.validate_path (get_dir test_ctxt) r ["system"; "login"; "user"])) true
let test_validate_path_garbage_after_value 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"; "foo"; "bar"])) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (raises_validation_error (fun () -> ignore @@ RT.validate_path (get_dir test_ctxt) r ["system"; "host-name"; "foo"; "bar"])) true
let test_validate_path_valueless_node_with_value 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"; "options"; "reboot-on-panic"; "fgsfds"])) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (raises_validation_error (fun () -> ignore @@ RT.validate_path (get_dir test_ctxt) r ["system"; "options"; "reboot-on-panic"; "fgsfds"])) true
let test_validate_path_valueless_node_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"; "options"; "reboot-on-panic"])
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ let test p =
+ let _ = RT.validate_path (get_dir test_ctxt) r p in
+ RT.split_path r p
+ in
+ assert_equal (test ["system"; "options"; "reboot-on-panic"])
(["system"; "options"; "reboot-on-panic"], None)
let test_is_multi_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 (is_multi r ["system"; "ntp-server"]) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_multi r ["system"; "ntp-server"]) true
let test_is_multi_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 (is_multi r ["system"; "host-name"]) false
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_multi r ["system"; "host-name"]) false
let test_is_secret_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 (is_secret r ["system"; "login"; "password"]) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_secret r ["system"; "login"; "password"]) true
let test_is_secret_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 (is_secret r ["system"; "login"; "user"; "full-name"]) false
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_secret r ["system"; "login"; "user"; "full-name"]) false
let test_is_hidden_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 (is_hidden r ["system"; "options"; "enable-dangerous-features"]) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_hidden r ["system"; "options"; "enable-dangerous-features"]) true
let test_is_hidden_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 (is_hidden r ["system"; "login"; "user"; "full-name"]) false
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_hidden r ["system"; "login"; "user"; "full-name"]) false
let test_is_tag_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 (is_tag r ["system"; "login"; "user"]) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_tag r ["system"; "login"; "user"]) true
let test_is_tag_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 (is_tag r ["system"; "login"]) false
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_tag r ["system"; "login"]) false
let test_is_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 (is_leaf r ["system"; "login"; "user"; "full-name"]) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_leaf r ["system"; "login"; "user"; "full-name"]) true
let test_is_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 (is_leaf r ["system"; "login"; "user"]) false
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_leaf r ["system"; "login"; "user"]) false
let test_is_valueless_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 (is_valueless r ["system"; "options"; "reboot-on-panic"]) true
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_valueless r ["system"; "options"; "reboot-on-panic"]) true
let test_is_valueless_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 (is_valueless r ["system"; "login"; "user"; "full-name"]) false
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.is_valueless r ["system"; "login"; "user"; "full-name"]) false
+(* keep_order not yet implemented *)
+(*
let test_get_keep_order_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
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (get_keep_order r ["system"; "login"; "user"]) true
let test_get_keep_order_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
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
assert_equal (get_keep_order r ["system"; "login"; "user"; "full-name"]) false
-
+*)
let test_get_owner_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 (get_owner r ["system"; "login"]) (Some "login")
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.get_owner r ["system"; "login"]) (Some "login")
let test_get_owner_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 (get_owner r ["system"; "login"; "user"]) None
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.get_owner r ["system"; "login"; "user"]) None
let test_get_help_string_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 (get_help_string r ["system"; "login"; "user"; "full-name"]) ("User full name")
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.get_help_string r ["system"; "login"; "user"; "full-name"]) ("User full name")
let test_get_help_string_default 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 (get_help_string r ["system"; "host-name"]) ("No help available")
+ let r = VT.make RT.default_data "root" in
+ let r = RT.load_from_xml r (in_testdata_dir test_ctxt ["interface_definition_sample.xml"]) in
+ assert_equal (RT.get_help_string r ["system"; "host-name"]) ("No help available")
let suite =
- "Util tests" >::: [
+ "Vyconf reference tree 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;
@@ -188,8 +205,6 @@ let suite =
"test_is_leaf_invalid" >:: test_is_leaf_invalid;
"test_is_valueless_valid" >:: test_is_valueless_valid;
"test_is_valueless_invalid" >:: test_is_valueless_invalid;
- "test_get_keep_order_valid" >:: test_get_keep_order_valid;
- "test_get_keep_order_invalid" >:: test_get_keep_order_invalid;
"test_get_owner_valid" >:: test_get_owner_valid;
"test_get_owner_invalid" >:: test_get_owner_invalid;
"test_get_help_string_valid" >:: test_get_help_string_valid;
diff --git a/test/session_test.ml b/test/session_test.ml
index a3a1fb0..5d31030 100644
--- a/test/session_test.ml
+++ b/test/session_test.ml
@@ -1,8 +1,10 @@
+[@@@ocaml.warning "-27"]
+
open OUnit2
-open Session
+open Vyconfd_config.Session
-module CT = Config_tree
-module RT = Reference_tree
+module CT = Vyos1x.Config_tree
+module RT = Vyos1x.Reference_tree
(* I'm not sure if we want to account for superfluous spaces inside the strings,
diff --git a/test/util_test.ml b/test/util_test.ml
index 2f5bf5d..5e348fc 100644
--- a/test/util_test.ml
+++ b/test/util_test.ml
@@ -1,22 +1,26 @@
+[@@@ocaml.warning "-27"]
+
open OUnit2
-open Util
+
+module RT = Vyos1x.Reference_tree
+module U = Vyos1x.Util
let test_find_xml_child_existent test_ctxt =
let elem = Xml.Element ("foo", [],
[Xml.Element ("bar", [], []);
Xml.PCData "baz"])
in
- match (find_xml_child "bar" elem) with
+ match (RT.find_xml_child "bar" elem) with
| None -> assert_failure "find_xml_child returned None"
| Some x -> assert_equal (Xml.tag x) "bar"
let test_find_xml_child_nonexistent test_ctxt =
let elem = Xml.Element ("foo", [], [Xml.Element ("quux", [], [])]) in
- assert_equal (find_xml_child "bar" elem) None
+ assert_equal (RT.find_xml_child "bar" elem) None
let test_string_of_list test_ctxt =
let path = ["foo"; "bar"; "baz"] in
- assert_equal (String.trim (string_of_list path)) "foo bar baz"
+ assert_equal (String.trim (U.string_of_list path)) "foo bar baz"
let suite =
"Util tests" >::: [
diff --git a/test/value_checker_test.ml b/test/value_checker_test.ml
index 16ad6e4..da71cb2 100644
--- a/test/value_checker_test.ml
+++ b/test/value_checker_test.ml
@@ -1,49 +1,52 @@
open OUnit2
-open Value_checker
+
+module VC = Vyos1x.Value_checker
let get_dir test_ctxt = in_testdata_dir test_ctxt ["validators"]
+let buf = Buffer.create 4096
+
let raises_bad_validator f =
try ignore @@ f (); false
- with Bad_validator _ -> true
+ with VC.Bad_validator _ -> true
let test_check_regex_valid test_ctxt =
- let c = Regex "[a-z]+" in
+ let c = VC.Regex "[a-z]+" in
let v = "fgsfds" in
- assert_equal (validate_value (get_dir test_ctxt) c v) true
+ assert_equal (VC.validate_value (get_dir test_ctxt) buf c v) true
let test_check_regex_invalid test_ctxt =
- let c = Regex "[a-z]+" in
+ let c = VC.Regex "[a-z]+" in
let v = "FGSFDS" in
- assert_equal (validate_value (get_dir test_ctxt) c v) false
+ assert_equal (VC.validate_value (get_dir test_ctxt) buf c v) false
let test_check_external_valid test_ctxt =
- let c = External ("anything", None) in
+ let c = VC.External ("anything", None) in
let v = "fgsfds" in
- assert_equal (validate_value (get_dir test_ctxt) c v) true
+ assert_equal (VC.validate_value (get_dir test_ctxt) buf c v) true
let test_check_external_invalid test_ctxt =
- let c = External ("nothing", None) in
+ let c = VC.External ("nothing", None) in
let v = "fgsfds" in
- assert_equal (validate_value (get_dir test_ctxt) c v) false
+ assert_equal (VC.validate_value (get_dir test_ctxt) buf c v) false
let test_check_external_bad_validator test_ctxt =
- let c = External ("invalid", None) in
+ let c = VC.External ("invalid", None) in
let v = "fgsfds" in
assert_bool "Invalid validator was executed successfully"
- (raises_bad_validator (fun () -> validate_value (get_dir test_ctxt) c v))
+ (raises_bad_validator (fun () -> VC.validate_value (get_dir test_ctxt) buf c v))
let test_validate_any_valid test_ctxt =
- let cs = [Regex "\\d+"; Regex "[a-z]+"; External ("anything", None)] in
- assert_equal (validate_any (get_dir test_ctxt) cs "AAAA") true
+ let cs = [VC.Regex "\\d+"; VC.Regex "[a-z]+"; VC.External ("anything", None)] in
+ assert_equal (VC.validate_any (get_dir test_ctxt) cs "AAAA") None
let test_validate_any_invalid test_ctxt =
- let cs = [Regex "\\d+"; Regex "[a-z]+"] in
- assert_equal (validate_any (get_dir test_ctxt) cs "AAAA") false
+ let cs = [VC.Regex "\\d+"; VC.Regex "[a-z]+"] in
+ assert_equal (VC.validate_any (get_dir test_ctxt) cs "AAAA") None
let test_validate_any_no_constraints test_ctxt =
let cs = [] in
- assert_equal (validate_any (get_dir test_ctxt) cs "foo") true
+ assert_equal (VC.validate_any (get_dir test_ctxt) cs "foo") None
let suite =
"VyConf value checker tests" >::: [
diff --git a/test/vyconf_config_test.ml b/test/vyconf_config_test.ml
index ba77d1c..acf0f2b 100644
--- a/test/vyconf_config_test.ml
+++ b/test/vyconf_config_test.ml
@@ -1,5 +1,5 @@
open OUnit2
-open Vyconf_config
+open Vyconfd_config.Vyconf_config
let try_load file =
let conf = load file in
@@ -11,8 +11,7 @@ let try_load_fail file err =
let conf = load file in
match conf with
| Ok _ -> assert_failure err
- | Error msg -> ()
-
+ | Error _ -> ()
let test_load_nonexistent_file test_ctxt =
(* Please don't create this file there! *)
diff --git a/test/vylist_test.ml b/test/vylist_test.ml
index c6bd993..1bcf21b 100644
--- a/test/vylist_test.ml
+++ b/test/vylist_test.ml
@@ -1,5 +1,7 @@
+[@@@ocaml.warning "-27"]
+
open OUnit2
-open Vylist
+open Vyos1x.Vylist
(* Searching for an element that is in the list gives Some that_element *)
let test_find_existent test_ctxt =
diff --git a/test/vytree_load_test.ml b/test/vytree_load_test.ml
index b56e130..cd8cc8d 100644
--- a/test/vytree_load_test.ml
+++ b/test/vytree_load_test.ml
@@ -1,3 +1,8 @@
+[@@@ocaml.warning "-27"]
+
+module VT = Vyos1x.Vytree
+module VL = Vyos1x.Vylist
+
let max = 9999
(* Path length *)
@@ -15,16 +20,16 @@ let insert_full tree path data =
| [] -> tree
| p :: ps ->
let basepath = basepath @ [p] in
- let tree = Vytree.insert tree basepath data in
+ let tree = VT.insert tree basepath data in
aux tree ps basepath data
in
- let existent_path = Vytree.get_existent_path tree path in
- let rest = Vylist.complement path existent_path in
+ let existent_path = VT.get_existent_path tree path in
+ let rest = VL.complement path existent_path in
aux tree rest existent_path ()
let rec add_many_children t n basepath data =
if n >= 0 then
- let t = Vytree.insert t (basepath @ [(string_of_int n)]) () in
+ let t = VT.insert t (basepath @ [(string_of_int n)]) () in
add_many_children t (n - 1) basepath data
else t
@@ -39,13 +44,13 @@ let rec do_inserts tree child n =
do_inserts tree child (n - 1)
else tree
-let tree = Vytree.make () "root"
+let tree = VT.make () "root"
(* Add a hundred children *)
let tree = add_many_children tree max_children [] ()
(* Use the last child to ensure that the child list is traversed
to the end every time *)
-let name = List.nth (Vytree.list_children tree) (max_children - 1)
+let name = List.nth (VT.list_children tree) (max_children - 1)
let _ = do_inserts tree name max_paths
diff --git a/test/vytree_test.ml b/test/vytree_test.ml
index 6133fb3..ecd75eb 100644
--- a/test/vytree_test.ml
+++ b/test/vytree_test.ml
@@ -1,5 +1,7 @@
+[@@@ocaml.warning "-27"]
+
open OUnit2
-open Vytree
+open Vyos1x.Vytree
(* Destructuting a freshly made node gives us what
we made it from *)
@@ -148,7 +150,7 @@ let test_merge_children_no_duplicates test_ctxt =
[make_full () "foo" [make () "bar"];
make () "bar";
make_full () "baz" [make () "quuz"]] in
- let node' = merge_children (fun x y -> x) node in
+ let node' = merge_children (fun x y -> x) (fun x y -> compare x y) node in
assert_equal (list_children node') ["foo"; "bar"; "baz"]
@@ -160,7 +162,7 @@ let test_merge_children_has_duplicates test_ctxt =
[make_full () "foo" [make () "bar"];
make () "quux";
make_full () "foo" [make () "baz"]] in
- let node' = merge_children (fun x y -> x) node in
+ let node' = merge_children (fun x y -> x) (fun x y -> compare x y) node in
assert_equal (list_children node') ["foo"; "quux"];
assert_equal (get node' ["foo"] |> list_children) ["bar"; "baz"]