diff options
Diffstat (limited to 'lib/configuration/tests')
| -rw-r--r-- | lib/configuration/tests/configuration.t | 77 | ||||
| -rw-r--r-- | lib/configuration/tests/dune | 11 | ||||
| -rw-r--r-- | lib/configuration/tests/errors.t | 119 | ||||
| -rw-r--r-- | lib/configuration/tests/tree.t | 161 |
4 files changed, 368 insertions, 0 deletions
diff --git a/lib/configuration/tests/configuration.t b/lib/configuration/tests/configuration.t new file mode 100644 index 0000000..a732db6 --- /dev/null +++ b/lib/configuration/tests/configuration.t @@ -0,0 +1,77 @@ +The configuration is written in JSON5 format. + +Minimal configuration file with nothing: + + $ tests -configuration <<EOF + > { "content" : [] } + > + > EOF + + +Trailing coma are accepted: + + $ tests -configuration <<EOF + > { "content" : + > [ + > { + > "id": "entity", + > }, + > ] + > } + > + > EOF + +Comments are accepted: + + $ tests -configuration <<EOF + > { "content" : + > [ + > { + > // This is a comment in the file + > "id": "entity", + > } + > ] + > } + > + > EOF + +Cycles between elements are accepted when they are not mandatory to each other + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user", + > "multivaluated": true + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user", + > "section": [ + > { + > "field": [ + > { + > "name": "entity", + > "label": {}, + > "type": { "content": "entity", } + > } + > ] + > } + > ] + > } + > ] + > } + + diff --git a/lib/configuration/tests/dune b/lib/configuration/tests/dune new file mode 100644 index 0000000..c5913da --- /dev/null +++ b/lib/configuration/tests/dune @@ -0,0 +1,11 @@ +; Add the test library in the path + +(env + (_ + (binaries %{project_root}/test/tests.exe))) + +; And depend of it. The binary will be available in the +; cram tests under the name "tests" + +(cram + (deps %{bin:tests})) diff --git a/lib/configuration/tests/errors.t b/lib/configuration/tests/errors.t new file mode 100644 index 0000000..6b5584e --- /dev/null +++ b/lib/configuration/tests/errors.t @@ -0,0 +1,119 @@ +Differents invalid configuration. All of them shall report the error properly + +Every content shall have an identifier + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "key": "", + > } + > ] + > } + > EOF + in field "content": + while decoding a list: + element 0: + Expected an object with an attribute "id", but got { "key": "" } + +The content ID cannot be empty: + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "", + > } + > ] + > } + > EOF + in field "content": + while decoding a list: + element 0: in field "id": Expected a non empty identifier, but got "" + +The content ID cannot be contains "." (this charater is used internaly): + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "foo.bar", + > } + > ] + > } + > EOF + in field "content": + while decoding a list: + element 0: + in field "id": + Expected an identifier with only the accepted characters, but got + "foo.bar" + +A reference shall point to an existing content: + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "content", + > "section": [ + > { + > "field": [ + > { + > "name": "name", + > "label": {}, + > "type": { + > "content": "yes_no" + > } + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + Undefined target "yes_no". Expected existing list or content, but got + { "content": "yes_no" } + +Cycles between required content are not accepted + + $ tests -configuration <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "required": true, + > "type": { + > "content": "user", + > "multivaluated": true, + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user", + > "section": [ + > { + > "field": [ + > { + > "name": "entity", + > "label": {}, + > "required": true, + > "type": { "content": "entity", } + > } + > ] + > } + > ] + > } + > ] + > } + Dependency circle found between: entity user diff --git a/lib/configuration/tests/tree.t b/lib/configuration/tests/tree.t new file mode 100644 index 0000000..b69c830 --- /dev/null +++ b/lib/configuration/tests/tree.t @@ -0,0 +1,161 @@ +This test display the dependency tree between root contents after loading the +configuration. + +Each reference field introduce a dependency between the content having the field +and the content targeted by the field. + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > "multivaluated": true + > } + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + digraph G { + entity; + user_type_list; + + + entity -> user_type_list; + + } + +The tree only contains root elements. Links between subcontent are reported as +link between their respective root content. + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details", + > "section": [ + > { + > "field": [ + > { + > "name": "user_type", + > "label": {}, + > "type": { + > "content": "user_type_list", + > } + > } + > ] + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list" + > } + > ] + > } + > EOF + digraph G { + entity; + user_type_list; + + + entity -> user_type_list; + + } + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details", + > "section": [ + > { + > "field": [ + > { + > "name": "reference", + > "label": {}, + > "type": { "content": "user-details", } + > } + > ] + > } + > ] + > } + > ] + > }, + > { + > "id": "user_type_list", + > "subcontent": [ + > { + > "id": "user-details", + > } + > ] + > } + > ] + > } + > EOF + digraph G { + entity; + user_type_list; + + + entity -> user_type_list; + + } + +A content is allowed to loop to itself, directly or indirectly: + + $ tests -configuration -tree <<EOF + > { + > "content": [ + > { + > "id": "entity", + > "subcontent": [ + > { + > "id": "details", + > "section": [ + > { + > "field": [ + > { + > "name": "entities", + > "label": {}, + > "type": { "content": "entity", } + > } + > ] + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + digraph G { + entity; + + + entity -> entity; + + } + + |
