You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/02/21 07:21:47 UTC

[buildstream] 01/01: tests: Test that user specified plugins shadow core plugins

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/test-plugin-shadowing
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit dd986d9456e2b837d4ce2f6815a01a0bf18d1c51
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Mon Feb 21 16:17:57 2022 +0900

    tests: Test that user specified plugins shadow core plugins
    
    Fixes #1555
---
 tests/plugins/shadow.py                  | 47 ++++++++++++++++++++++++++++++++
 tests/plugins/shadow/elements/manual.bst |  1 +
 tests/plugins/shadow/plugins/manual.py   | 19 +++++++++++++
 tests/plugins/shadow/project.conf        |  8 ++++++
 4 files changed, 75 insertions(+)

diff --git a/tests/plugins/shadow.py b/tests/plugins/shadow.py
new file mode 100644
index 0000000..e69373a
--- /dev/null
+++ b/tests/plugins/shadow.py
@@ -0,0 +1,47 @@
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+#
+# This test case ensures that user provided plugins appropriately shadow
+# core defined plugins, which is a behavior that is required in order to
+# make it safe for BuildStream to add more plugins in the future without
+# stomping on plugin namespace.
+#
+
+import os
+import pytest
+
+from buildstream.testing import cli  # pylint: disable=unused-import
+from buildstream import _yaml
+
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "shadow")
+
+
+def update_project(project_path, updated_configuration):
+    project_conf_path = os.path.join(project_path, "project.conf")
+    project_conf = _yaml.roundtrip_load(project_conf_path)
+
+    project_conf.update(updated_configuration)
+
+    _yaml.roundtrip_dump(project_conf, project_conf_path)
+
+
+#
+# Run the test with and without shadowing the "manual" plugin.
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("shadow", [True, False], ids=["shadowed", "not-shadowed"])
+def test_manual(cli, datafiles, shadow):
+    project = str(datafiles)
+
+    if shadow:
+        update_project(project, {"plugins": [{"origin": "local", "path": "plugins", "elements": ["manual"]}]})
+
+    result = cli.run(project=project, args=["show", "manual.bst"])
+    result.assert_success()
+
+    if shadow:
+        assert "This is an overridden manual element" in result.stderr
+    else:
+        assert "This is an overridden manual element" not in result.stderr
diff --git a/tests/plugins/shadow/elements/manual.bst b/tests/plugins/shadow/elements/manual.bst
new file mode 100644
index 0000000..4d7f702
--- /dev/null
+++ b/tests/plugins/shadow/elements/manual.bst
@@ -0,0 +1 @@
+kind: manual
diff --git a/tests/plugins/shadow/plugins/manual.py b/tests/plugins/shadow/plugins/manual.py
new file mode 100644
index 0000000..eafff19
--- /dev/null
+++ b/tests/plugins/shadow/plugins/manual.py
@@ -0,0 +1,19 @@
+from buildstream import Element
+
+
+class Manual(Element):
+    BST_MIN_VERSION = "2.0"
+
+    def configure(self, node):
+        self.info("This is an overridden manual element")
+
+    def preflight(self):
+        pass
+
+    def get_unique_key(self):
+        return {}
+
+
+# Plugin entry point
+def setup():
+    return Manual
diff --git a/tests/plugins/shadow/project.conf b/tests/plugins/shadow/project.conf
new file mode 100644
index 0000000..738051a
--- /dev/null
+++ b/tests/plugins/shadow/project.conf
@@ -0,0 +1,8 @@
+# This project.conf gets rewritten for each plugin loading test
+name: test
+
+# Required BuildStream version
+min-version: 2.0
+
+# Subdirectory where elements are stored
+element-path: elements