summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-17 20:11:37 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-20 18:29:14 +0900
commit50400e123ef7f9aa8b2b1a779e2651dccf4f4df0 (patch)
tree1bc87fd7cb51b66b3c4532609bc30e01a44779a9
parent6b63828cd96a86e75aaa5ea32a7ceadccaea4185 (diff)
downloadbuildstream-50400e123ef7f9aa8b2b1a779e2651dccf4f4df0.tar.gz
tests/pipeline/load.py: Testing source without load_ref() implementation
Test that we have no error when loading a project that doesnt use project.refs, and that we get the expected graceful failure when attempting to use project.refs with a Source which doesnt support it.
-rw-r--r--tests/pipeline/load.py34
-rw-r--r--tests/pipeline/load/noloadref/noloadref.bst7
-rw-r--r--tests/pipeline/load/noloadref/plugins/noloadref.py36
-rw-r--r--tests/pipeline/load/noloadref/project.refs6
4 files changed, 83 insertions, 0 deletions
diff --git a/tests/pipeline/load.py b/tests/pipeline/load.py
index 42b563ac1..29ceb6dde 100644
--- a/tests/pipeline/load.py
+++ b/tests/pipeline/load.py
@@ -1,5 +1,7 @@
import os
import pytest
+from buildstream._exceptions import ErrorDomain
+from buildstream import _yaml
from tests.testutils.runcli import cli
DATA_DIR = os.path.join(
@@ -183,3 +185,35 @@ def test_except_elements(cli, datafiles, elements, exceptions, results):
# are removed.
element_list = cli.get_pipeline(basedir, elements, except_=exceptions, scope='all')
assert element_list == results
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'noloadref'))
+@pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')])
+def test_unsupported_load_ref(cli, datafiles, ref_storage):
+ basedir = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Generate project with access to the noloadref plugin and project.refs enabled
+ #
+ config = {
+ 'name': 'test',
+ 'ref-storage': ref_storage,
+ 'plugins': [
+ {
+ 'origin': 'local',
+ 'path': 'plugins',
+ 'sources': {
+ 'noloadref': 0
+ }
+ }
+ ]
+ }
+ _yaml.dump(config, os.path.join(basedir, 'project.conf'))
+
+ result = cli.run(project=basedir, silent=True, args=['show', 'noloadref.bst'])
+
+ # There is no error if project.refs is not in use, otherwise we
+ # assert our graceful failure
+ if ref_storage == 'inline':
+ result.assert_success()
+ else:
+ result.assert_main_error(ErrorDomain.SOURCE, 'unsupported-load-ref')
diff --git a/tests/pipeline/load/noloadref/noloadref.bst b/tests/pipeline/load/noloadref/noloadref.bst
new file mode 100644
index 000000000..23a52ef8f
--- /dev/null
+++ b/tests/pipeline/load/noloadref/noloadref.bst
@@ -0,0 +1,7 @@
+kind: import
+description: |
+
+ Import a source which does not support the load_ref() method
+
+sources:
+- kind: noloadref
diff --git a/tests/pipeline/load/noloadref/plugins/noloadref.py b/tests/pipeline/load/noloadref/plugins/noloadref.py
new file mode 100644
index 000000000..0cc457f07
--- /dev/null
+++ b/tests/pipeline/load/noloadref/plugins/noloadref.py
@@ -0,0 +1,36 @@
+from buildstream import Source, Consistency
+
+
+# Just a dummy plugin which does not support the new load_ref() method.
+#
+# Use this to test that the core behaves as expected with such plugins.
+#
+class NoLoadRefSource(Source):
+
+ def configure(self, node):
+ pass
+
+ def preflight(self):
+ pass
+
+ def get_unique_key(self):
+ return {}
+
+ def get_consistency(self):
+ return Consistency.CACHED
+
+ def get_ref(self):
+ return None
+
+ def set_ref(self, ref, node):
+ pass
+
+ def fetch(self):
+ pass
+
+ def stage(self, directory):
+ pass
+
+
+def setup():
+ return NoLoadRefSource
diff --git a/tests/pipeline/load/noloadref/project.refs b/tests/pipeline/load/noloadref/project.refs
new file mode 100644
index 000000000..b06a4577d
--- /dev/null
+++ b/tests/pipeline/load/noloadref/project.refs
@@ -0,0 +1,6 @@
+# A project.refs file with an existing ref for the noloadref element
+#
+projects:
+ test:
+ noloadref.bst:
+ - ref: dummy