summaryrefslogtreecommitdiff
path: root/test/config_tree_test.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-09-12 21:10:21 +0700
committerDaniil Baturin <daniil@baturin.org>2017-09-12 21:10:21 +0700
commitdd67f0333363d3afb0f8d42aaed94f52712dd759 (patch)
tree3467040ab5d3e4080e5b74edf6601fb82e98db0b /test/config_tree_test.ml
parentbc2c1a032a4aad1d5c3f5047d51f86bf8370b163 (diff)
parent5761be1601db95ceeec49104c502902939e194d6 (diff)
downloadvyconf-dd67f0333363d3afb0f8d42aaed94f52712dd759.tar.gz
vyconf-dd67f0333363d3afb0f8d42aaed94f52712dd759.zip
Merge branch 'master' of github.com:vyos/vyconf
Diffstat (limited to 'test/config_tree_test.ml')
-rw-r--r--test/config_tree_test.ml103
1 files changed, 102 insertions, 1 deletions
diff --git a/test/config_tree_test.ml b/test/config_tree_test.ml
index 7057b94..ad79df3 100644
--- a/test/config_tree_test.ml
+++ b/test/config_tree_test.ml
@@ -92,6 +92,102 @@ let test_set_ephemeral test_ctxt =
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
+
+let config_tree_of_path path = CT.make "root" |> set path None
+
+let set_in_config_tree ~how ?(path=[]) ?value =
+ let node = config_tree_of_path path in
+ how node path value
+
+let toggle_in_config_tree ~how ?(path=[]) ?(value=false) =
+ let node = config_tree_of_path path in
+ how node path value
+
+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 foobar = ["foo"; "bar"]
+
+(*** Rendering tests *)
+
+(**** Standalone rendering *)
+let test_render_nested_empty_with_comment test_ctxt =
+ let rendered = CT.render @@
+ 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 { }
+ }
+}"
+
+(**** Reftree-based rendering *)
+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 node in
+ let desired_rendered_form =
+"root {
+ system {
+ login {
+ user full-name \"name here\";
+ }
+ }
+}"
+ in
+ assert_equal rendered_curly_config desired_rendered_form
+
+let test_render_rt_unspecified_node test_ctxt =
+ let reftree = load_reftree test_ctxt in
+ let path = ["system"; "login"; "user"; "unspecified_node"] 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 node in
+ let desired_rendered_form =
+"root {
+ system {
+ login {
+ user unspecified_node \"name here\";
+ }
+ }
+}"
+ in
+ assert_equal rendered_curly_config desired_rendered_form
+
let suite =
"VyConf config tree tests" >::: [
"test_set_create_node" >:: test_set_create_node;
@@ -105,7 +201,12 @@ let suite =
"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_rt_tag_node" >:: test_render_rt_tag_node;
+ "test_render_rt_unspecified_node" >:: test_render_rt_unspecified_node
]
let () =
- run_test_tt_main suite
+ run_test_tt_main suite