You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:30:45 UTC
[buildstream] 02/07: Add element node validations
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch validation
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 94570a3c4338d344e9d3ca0759c61a6b2d3ba1c1
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Wed Sep 6 17:50:24 2017 +0100
Add element node validations
---
buildstream/_loader.py | 9 +++++++++
tests/loader/basics.py | 12 ++++++++++++
tests/loader/basics/onefile/elements/invalidkey.bst | 3 +++
tests/loader/basics/onefile/elements/invalidsourcekey.bst | 6 ++++++
4 files changed, 30 insertions(+)
diff --git a/buildstream/_loader.py b/buildstream/_loader.py
index 72b7ed3..b7a1ccb 100644
--- a/buildstream/_loader.py
+++ b/buildstream/_loader.py
@@ -211,6 +211,15 @@ class LoadElement():
# These are shared with the owning Loader object
self.basedir = basedir
+ # Ensure the root node is valid
+ _yaml.validate_node(self.data, [
+ 'kind', 'depends', 'sources',
+ 'variables', 'environment',
+ 'config', 'public', 'description',
+ 'arches', 'variants', 'host-arches',
+ 'choice'
+ ])
+
# Process arch conditionals
resolve_arch(self.data, self.host_arch, self.target_arch)
diff --git a/tests/loader/basics.py b/tests/loader/basics.py
index 4830702..99f5edb 100644
--- a/tests/loader/basics.py
+++ b/tests/loader/basics.py
@@ -72,3 +72,15 @@ def test_fail_fullpath_target(datafiles):
loader = Loader(basedir, fullpath, None, None, None, [])
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'onefile'))
+def test_invalid_key(datafiles):
+
+ basedir = os.path.join(datafiles.dirname, datafiles.basename)
+ loader = Loader(basedir, 'elements/invalidkey.bst', None, None, None, [])
+
+ with pytest.raises(LoadError) as exc:
+ element = loader.load()
+
+ assert (exc.value.reason == LoadErrorReason.INVALID_YAML)
diff --git a/tests/loader/basics/onefile/elements/invalidkey.bst b/tests/loader/basics/onefile/elements/invalidkey.bst
new file mode 100644
index 0000000..5674ab7
--- /dev/null
+++ b/tests/loader/basics/onefile/elements/invalidkey.bst
@@ -0,0 +1,3 @@
+kind: pony
+description: This is the pony
+wings: blue
diff --git a/tests/loader/basics/onefile/elements/invalidsourcekey.bst b/tests/loader/basics/onefile/elements/invalidsourcekey.bst
new file mode 100644
index 0000000..5677af3
--- /dev/null
+++ b/tests/loader/basics/onefile/elements/invalidsourcekey.bst
@@ -0,0 +1,6 @@
+kind: pony
+description: This is the pony
+sources:
+ - kind: ponyland
+ url: ptp://pw.ponies.p/
+ weather: great