summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/interface_definitions/login_sample.xml23
-rw-r--r--test/data/interface_definitions/system_sample.xml63
-rw-r--r--test/reference_tree_test.ml19
3 files changed, 105 insertions, 0 deletions
diff --git a/test/data/interface_definitions/login_sample.xml b/test/data/interface_definitions/login_sample.xml
new file mode 100644
index 0000000..b74a415
--- /dev/null
+++ b/test/data/interface_definitions/login_sample.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<interfaceDefinition>
+ <node name="login" owner="login">
+ <children>
+ <tagNode name="user">
+ <properties>
+ <help>User name</help>
+ <constraint>
+ <regex>[a-z][a-zA-Z0-9]+</regex>
+ </constraint>
+ <constraintErrorMessage>User name must start with a letter and consist of letters and digits</constraintErrorMessage>
+ </properties>
+ <children>
+ <leafNode name="full-name">
+ <properties>
+ <help>User full name</help>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ </children>
+ </node>
+</interfaceDefinition>
diff --git a/test/data/interface_definitions/system_sample.xml b/test/data/interface_definitions/system_sample.xml
new file mode 100644
index 0000000..c6185c0
--- /dev/null
+++ b/test/data/interface_definitions/system_sample.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0"?>
+<interfaceDefinition>
+ <node name="system">
+ <children>
+ <node name="login" owner="login">
+ <children>
+ <tagNode name="user">
+ <keepChildOrder/>
+ <properties>
+ <help>User name</help>
+ <constraint>
+ <regex>[a-zA-Z][a-zA-Z0-9\-]+</regex>
+ </constraint>
+ <constraintErrorMessage>User name must start with a letter and consist of letters and digits</constraintErrorMessage>
+ </properties>
+ <children>
+ <leafNode name="full-name">
+ <properties>
+ <help>User full name</help>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ <leafNode name="password">
+ <properties>
+ <help>A password</help>
+ <secret/>
+ </properties>
+ </leafNode>
+ </children>
+ </node>
+ <leafNode name="host-name">
+ <properties>
+ <constraint>
+ <regex>[a-zA-Z][a-zA-Z0-9\-]</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="ntp-server">
+ <properties>
+ <help>NTP server address</help>
+ <multi/>
+ </properties>
+ </leafNode>
+ <node name="options">
+ <children>
+ <leafNode name="reboot-on-panic">
+ <properties>
+ <help>Reboot automatically if kernel panic occurs</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="enable-dangerous-features">
+ <properties>
+ <help>Enable dangerous features</help>
+ <hidden/>
+ </properties>
+ </leafNode>
+ </children>
+ </node>
+ </children>
+ </node>
+</interfaceDefinition>
diff --git a/test/reference_tree_test.ml b/test/reference_tree_test.ml
index 8002bdf..a3125be 100644
--- a/test/reference_tree_test.ml
+++ b/test/reference_tree_test.ml
@@ -3,6 +3,10 @@ open Reference_tree
let get_dir test_ctxt = in_testdata_dir test_ctxt ["validators"]
+let ok_or_failure result = match result with
+ | Ok value -> value
+ | Error msg -> assert_failure msg
+
let raises_validation_error f =
try ignore @@ f (); false
with Validation_error _ -> true
@@ -158,6 +162,19 @@ let test_get_help_string_default test_ctxt =
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 test_load_interface_definitions_children test_ctxt =
+ let interface_definitions_dir = in_testdata_dir test_ctxt ["interface_definitions"] in
+ let r = ok_or_failure (load_interface_definitions interface_definitions_dir) in
+ let children = Vytree.list_children r in
+ assert_equal children ["system"; "login"]
+
+let test_load_interface_definitions_leaves test_ctxt =
+ let interface_definitions_dir = in_testdata_dir test_ctxt ["interface_definitions"] in
+ let r = ok_or_failure (load_interface_definitions interface_definitions_dir) in
+ let has_system_leaf = is_leaf r ["system"; "login"; "user"; "full-name"] in
+ let has_login_leaf = is_leaf r ["login"; "user"; "full-name"] in
+ assert_equal (has_system_leaf && has_login_leaf) true
+
let suite =
"Util tests" >::: [
"test_load_valid_definition" >:: test_load_valid_definition;
@@ -189,6 +206,8 @@ let suite =
"test_get_owner_invalid" >:: test_get_owner_invalid;
"test_get_help_string_valid" >:: test_get_help_string_valid;
"test_get_help_string_default" >:: test_get_help_string_default;
+ "test_load_interface_definitions_children " >:: test_load_interface_definitions_children;
+ "test_load_interface_definitions_leaves" >:: test_load_interface_definitions_leaves
]
let () =