summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-09-23 02:35:41 +0600
committerDaniil Baturin <daniil@baturin.org>2015-09-23 02:35:41 +0600
commitfcb91a8a32e79f52e31b68180ed50c123cac5cb1 (patch)
tree257fb10fab55ddec01b9d8dc691b07f105aed466 /test
parent5b4deef7ca8916ebcc15062b32019b0488e039bc (diff)
downloadvyconf-fcb91a8a32e79f52e31b68180ed50c123cac5cb1.tar.gz
vyconf-fcb91a8a32e79f52e31b68180ed50c123cac5cb1.zip
Add more tests for set and delete.
Diffstat (limited to 'test')
-rw-r--r--test/config_tree_test.ml44
1 files changed, 37 insertions, 7 deletions
diff --git a/test/config_tree_test.ml b/test/config_tree_test.ml
index 516960d..dc9d239 100644
--- a/test/config_tree_test.ml
+++ b/test/config_tree_test.ml
@@ -2,20 +2,46 @@ open OUnit2
module VT = Vytree
module CT = Config_tree
-
+
+(* Setting a value of a node that doesn't exist should create the node *)
let test_set_create_node test_ctxt =
let path = ["foo"; "bar"] in
let node = CT.make "root" in
- let node = CT.set node path "baz" CT.ReplaceValue in
+ let node = CT.set node path (Some "baz") CT.ReplaceValue in
let values = CT.get_values node path in
assert_equal values ["baz"]
+(* Setting a value with AddValue behaviour should append the new value *)
+let test_set_add_value test_ctxt =
+ let path = ["foo"; "bar"] in
+ let node = CT.make "root" in
+ let node = CT.set node path (Some "baz") CT.AddValue in
+ let node = CT.set node path (Some "quux") CT.AddValue in
+ let values = CT.get_values node path in
+ assert_equal values ["baz"; "quux"]
+
+(* Setting a value with ReplaceValue behaviour should replace the value *)
+let test_set_replace_value test_ctxt =
+ let path = ["foo"; "bar"] in
+ let node = CT.make "root" in
+ let node = CT.set node path (Some "baz") CT.ReplaceValue in
+ let node = CT.set node path (Some "quux") CT.ReplaceValue in
+ let values = CT.get_values node path in
+ assert_equal values ["quux"]
+
+(* Creating a node without a value should work *)
+let test_create_valueless_node test_ctxt =
+ let path = ["foo"; "bar"] in
+ let node = CT.make "root" in
+ let node = CT.set node path None CT.AddValue in
+ assert_equal (CT.get_values node path) []
+
(* Deleting just one of many values should keep all other values intact *)
let test_delete_just_value test_ctxt =
let path = ["foo"; "bar"] in
let node = CT.make "root" in
- let node = CT.set node path "baz" CT.AddValue in
- let node = CT.set node path "quux" CT.AddValue in
+ let node = CT.set node path (Some "baz") CT.AddValue in
+ let node = CT.set node path (Some "quux") CT.AddValue in
let node = CT.delete node path (Some "quux") in
assert_equal (CT.get_values node path) ["baz"]
@@ -23,7 +49,7 @@ let test_delete_just_value test_ctxt =
let test_delete_last_value test_ctxt =
let path = ["foo"; "bar"] in
let node = CT.make "root" in
- let node = CT.set node path "baz" CT.AddValue in
+ let node = CT.set node path (Some "baz") CT.AddValue in
let node = CT.delete node path (Some "baz") in
assert_equal ((not (VT.exists node path)) && (VT.exists node ["foo"])) true
@@ -31,16 +57,20 @@ let test_delete_last_value test_ctxt =
let test_delete_subtree test_ctxt =
let path = ["foo"; "bar"] in
let node = CT.make "root" in
- let node = CT.set node path "baz" CT.AddValue in
- let node = CT.delete node path None in
+ let node = CT.set node path (Some "baz") CT.AddValue in
+ let node = CT.delete node ["foo"] None in
assert_equal (VT.list_children node) []
let suite =
"VyConf config tree tests" >::: [
"test_set_create_node" >:: test_set_create_node;
+ "test_set_add_value" >:: test_set_add_value;
+ "test_set_replace_value" >:: test_set_replace_value;
+ "test_create_valueless_node" >:: test_create_valueless_node;
"test_delete_just_value" >:: test_delete_just_value;
"test_delete_last_value" >:: test_delete_last_value;
+ "test_delete_subtree" >:: test_delete_subtree;
]
let () =