diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-08-30 22:17:16 -0400 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-08-31 12:39:13 -0400 |
commit | dc9b1a90e66e31cf65ecff65044fba6c7c310a3b (patch) | |
tree | fad116f392a3a17bc576c1b18c56dd390ecf96ed /tests/plugins | |
parent | 9a58d899b042ec7df28d55dc24719af3fa21d367 (diff) | |
download | buildstream-dc9b1a90e66e31cf65ecff65044fba6c7c310a3b.tar.gz |
plugin tests: Adding new tests with plugins loaded in a pipeline
o Testing that we can load a custom element or source
o Testing that we assert and trigger an error when the requested
format version of a plugin by the project is greater than the
reported version of the plugin
Diffstat (limited to 'tests/plugins')
17 files changed, 178 insertions, 0 deletions
diff --git a/tests/plugins/pipeline.py b/tests/plugins/pipeline.py new file mode 100644 index 000000000..868145a11 --- /dev/null +++ b/tests/plugins/pipeline.py @@ -0,0 +1,52 @@ +import os +import pytest + +from buildstream import Context, Project, Scope, PluginError +from buildstream._pipeline import Pipeline + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'pipeline', +) + + +def create_pipeline(tmpdir, basedir, target, variant): + context = Context('x86_64') + project = Project(basedir, 'x86_64') + + context.deploydir = os.path.join(str(tmpdir), 'deploy') + context.artifactdir = os.path.join(str(tmpdir), 'artifact') + + return Pipeline(context, project, target, variant) + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customsource')) +def test_customsource(datafiles, tmpdir): + + basedir = os.path.join(datafiles.dirname, datafiles.basename) + pipeline = create_pipeline(tmpdir, basedir, 'simple.bst', None) + assert(pipeline.target.get_kind() == "autotools") + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customelement')) +def test_customelement(datafiles, tmpdir): + + basedir = os.path.join(datafiles.dirname, datafiles.basename) + pipeline = create_pipeline(tmpdir, basedir, 'simple.bst', None) + assert(pipeline.target.get_kind() == "foo") + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionsource')) +def test_badversionsource(datafiles, tmpdir): + basedir = os.path.join(datafiles.dirname, datafiles.basename) + + with pytest.raises(PluginError) as exc: + pipeline = create_pipeline(tmpdir, basedir, 'simple.bst', None) + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionelement')) +def test_badversionelement(datafiles, tmpdir): + basedir = os.path.join(datafiles.dirname, datafiles.basename) + + with pytest.raises(PluginError) as exc: + pipeline = create_pipeline(tmpdir, basedir, 'simple.bst', None) diff --git a/tests/plugins/pipeline/badversionelement/customelements/__init__.py b/tests/plugins/pipeline/badversionelement/customelements/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/plugins/pipeline/badversionelement/customelements/__init__.py diff --git a/tests/plugins/pipeline/badversionelement/customelements/foo.py b/tests/plugins/pipeline/badversionelement/customelements/foo.py new file mode 100644 index 000000000..75536e87f --- /dev/null +++ b/tests/plugins/pipeline/badversionelement/customelements/foo.py @@ -0,0 +1,19 @@ +from buildstream import Element + + +class FooElement(Element): + + BST_FORMAT_VERSION = 5 + + def preflight(self): + pass + + def configure(self, node): + pass + + def get_unique_key(self): + return {} + + +def setup(): + return FooElement diff --git a/tests/plugins/pipeline/badversionelement/elements/simple.bst b/tests/plugins/pipeline/badversionelement/elements/simple.bst new file mode 100644 index 000000000..f949dc5b5 --- /dev/null +++ b/tests/plugins/pipeline/badversionelement/elements/simple.bst @@ -0,0 +1,4 @@ +kind: foo +description: Custom foo element +config: + some: thing diff --git a/tests/plugins/pipeline/badversionelement/project.conf b/tests/plugins/pipeline/badversionelement/project.conf new file mode 100644 index 000000000..66d0f5549 --- /dev/null +++ b/tests/plugins/pipeline/badversionelement/project.conf @@ -0,0 +1,12 @@ +name: pony +element-path: elements + +required-versions: + + # We provided bar at version 5, should be a conflict. + sources: + foo: 10 + +plugins: + sources: + - customelements diff --git a/tests/plugins/pipeline/badversionsource/customsources/__init__.py b/tests/plugins/pipeline/badversionsource/customsources/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/plugins/pipeline/badversionsource/customsources/__init__.py diff --git a/tests/plugins/pipeline/badversionsource/customsources/foo.py b/tests/plugins/pipeline/badversionsource/customsources/foo.py new file mode 100644 index 000000000..f50855fd1 --- /dev/null +++ b/tests/plugins/pipeline/badversionsource/customsources/foo.py @@ -0,0 +1,19 @@ +from buildstream import Source, Consistency + + +class BarSource(Source): + + BST_FORMAT_VERSION = 5 + + def preflight(self): + pass + + def configure(self, node): + pass + + def get_consistency(self): + return Consistency.INCONSISTENT + + +def setup(): + return BarSource diff --git a/tests/plugins/pipeline/badversionsource/elements/simple.bst b/tests/plugins/pipeline/badversionsource/elements/simple.bst new file mode 100644 index 000000000..7e0cc43b7 --- /dev/null +++ b/tests/plugins/pipeline/badversionsource/elements/simple.bst @@ -0,0 +1,6 @@ +kind: autotools +description: Custom foo source +sources: +- kind: foo + ref: 1.2.3 + uri: http://ponyland.com diff --git a/tests/plugins/pipeline/badversionsource/project.conf b/tests/plugins/pipeline/badversionsource/project.conf new file mode 100644 index 000000000..2925989d1 --- /dev/null +++ b/tests/plugins/pipeline/badversionsource/project.conf @@ -0,0 +1,12 @@ +name: pony +element-path: elements + +required-versions: + + # We provided bar at version 5, should be a conflict. + sources: + foo: 10 + +plugins: + sources: + - customsources diff --git a/tests/plugins/pipeline/customelement/elements/simple.bst b/tests/plugins/pipeline/customelement/elements/simple.bst new file mode 100644 index 000000000..fc48e3ba9 --- /dev/null +++ b/tests/plugins/pipeline/customelement/elements/simple.bst @@ -0,0 +1,4 @@ +kind: foo +description: Custom foo source +config: + pony-color: pink diff --git a/tests/plugins/pipeline/customelement/pluginelements/__init__.py b/tests/plugins/pipeline/customelement/pluginelements/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/plugins/pipeline/customelement/pluginelements/__init__.py diff --git a/tests/plugins/pipeline/customelement/pluginelements/foo.py b/tests/plugins/pipeline/customelement/pluginelements/foo.py new file mode 100644 index 000000000..823306ebc --- /dev/null +++ b/tests/plugins/pipeline/customelement/pluginelements/foo.py @@ -0,0 +1,17 @@ +from buildstream import Element + + +class FooElement(Element): + + def preflight(self): + pass + + def configure(self, node): + pass + + def get_unique_key(self): + return {} + + +def setup(): + return FooElement diff --git a/tests/plugins/pipeline/customelement/project.conf b/tests/plugins/pipeline/customelement/project.conf new file mode 100644 index 000000000..fa80eea01 --- /dev/null +++ b/tests/plugins/pipeline/customelement/project.conf @@ -0,0 +1,5 @@ +name: pony +element-path: elements +plugins: + elements: + - pluginelements diff --git a/tests/plugins/pipeline/customsource/elements/simple.bst b/tests/plugins/pipeline/customsource/elements/simple.bst new file mode 100644 index 000000000..7e0cc43b7 --- /dev/null +++ b/tests/plugins/pipeline/customsource/elements/simple.bst @@ -0,0 +1,6 @@ +kind: autotools +description: Custom foo source +sources: +- kind: foo + ref: 1.2.3 + uri: http://ponyland.com diff --git a/tests/plugins/pipeline/customsource/pluginsources/__init__.py b/tests/plugins/pipeline/customsource/pluginsources/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/plugins/pipeline/customsource/pluginsources/__init__.py diff --git a/tests/plugins/pipeline/customsource/pluginsources/foo.py b/tests/plugins/pipeline/customsource/pluginsources/foo.py new file mode 100644 index 000000000..d2b0d9c6d --- /dev/null +++ b/tests/plugins/pipeline/customsource/pluginsources/foo.py @@ -0,0 +1,17 @@ +from buildstream import Source, Consistency + + +class FooSource(Source): + + def preflight(self): + pass + + def configure(self, node): + pass + + def get_consistency(self): + return Consistency.INCONSISTENT + + +def setup(): + return FooSource diff --git a/tests/plugins/pipeline/customsource/project.conf b/tests/plugins/pipeline/customsource/project.conf new file mode 100644 index 000000000..0be4f201b --- /dev/null +++ b/tests/plugins/pipeline/customsource/project.conf @@ -0,0 +1,5 @@ +name: pony +element-path: elements +plugins: + sources: + - pluginsources |