diff options
author | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2019-03-15 14:39:07 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-03-25 11:46:44 +0000 |
commit | 98ad4e880ba87c29bd850771c88f160adc2590f0 (patch) | |
tree | 3cb5a6394bf5e39b8b63aac5752e90c6d31d3b5d /tests | |
parent | 85b86204a7114e0b388b65871258f562853240c0 (diff) | |
download | buildstream-98ad4e880ba87c29bd850771c88f160adc2590f0.tar.gz |
tests: check sources are pushed even if build fails
Adds a plugin build element that always fails. The test tries to build
an element of this kind.
Part of #440
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sourcecache/project/plugins/elements/always_fail.py | 32 | ||||
-rw-r--r-- | tests/sourcecache/project/plugins/elements/always_fail.yaml | 22 | ||||
-rw-r--r-- | tests/sourcecache/project/project.conf | 7 | ||||
-rw-r--r-- | tests/sourcecache/push.py | 39 |
4 files changed, 100 insertions, 0 deletions
diff --git a/tests/sourcecache/project/plugins/elements/always_fail.py b/tests/sourcecache/project/plugins/elements/always_fail.py new file mode 100644 index 000000000..99ef0d7de --- /dev/null +++ b/tests/sourcecache/project/plugins/elements/always_fail.py @@ -0,0 +1,32 @@ +# +# Copyright (C) 2019 Bloomberg Finance L.P. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. +# +# Authors: +# Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> +# + +from buildstream.element import ElementError +from buildstream.buildelement import BuildElement + + +class AlwaysFail(BuildElement): + + def assemble(self, sandbox): + raise ElementError("Always fails") + + +def setup(): + return AlwaysFail diff --git a/tests/sourcecache/project/plugins/elements/always_fail.yaml b/tests/sourcecache/project/plugins/elements/always_fail.yaml new file mode 100644 index 000000000..9934ab2f9 --- /dev/null +++ b/tests/sourcecache/project/plugins/elements/always_fail.yaml @@ -0,0 +1,22 @@ +# always-fail build element does not provide any default +# build commands +config: + + # Commands for configuring the software + # + configure-commands: [] + + # Commands for building the software + # + build-commands: [] + + # Commands for installing the software into a + # destination folder + # + install-commands: [] + + # Commands for stripping installed binaries + # + strip-commands: + - | + %{strip-binaries} diff --git a/tests/sourcecache/project/project.conf b/tests/sourcecache/project/project.conf index 854e38693..728f3faa1 100644 --- a/tests/sourcecache/project/project.conf +++ b/tests/sourcecache/project/project.conf @@ -2,3 +2,10 @@ name: test element-path: elements + +plugins: + +- origin: local + path: plugins/elements + elements: + always_fail: 0
\ No newline at end of file diff --git a/tests/sourcecache/push.py b/tests/sourcecache/push.py index 8fe06886b..f692136bb 100644 --- a/tests/sourcecache/push.py +++ b/tests/sourcecache/push.py @@ -24,6 +24,7 @@ import shutil import pytest from buildstream._context import Context +from buildstream._exceptions import ErrorDomain from buildstream._project import Project from buildstream import _yaml from buildstream.plugintestutils import cli # pylint: disable=unused-import @@ -181,3 +182,41 @@ def test_push_fail(cli, tmpdir, datafiles): .format(remote)) in res.stderr assert "Pushing" not in res.stderr assert "Pushed" not in res.stderr + + +@pytest.mark.datafiles(DATA_DIR) +def test_source_push_build_fail(cli, tmpdir, datafiles): + project_dir = str(datafiles) + cache_dir = os.path.join(str(tmpdir), 'cache') + + with create_artifact_share(os.path.join(str(tmpdir), 'share')) as share: + user_config = { + 'scheduler': { + 'pushers': 1 + }, + 'source-caches': { + 'url': share.repo, + 'push': True, + }, + 'cachedir': cache_dir, + } + cli.configure(user_config) + + repo = create_repo('git', str(tmpdir)) + ref = repo.create(os.path.join(project_dir, 'files')) + element_path = os.path.join(project_dir, 'elements') + + element_name = 'always-fail.bst' + element = { + 'kind': 'always_fail', + 'sources': [repo.source_config(ref=ref)] + } + _yaml.dump(element, os.path.join(element_path, element_name)) + + res = cli.run(project=project_dir, args=['build', 'always-fail.bst']) + res.assert_main_error(ErrorDomain.STREAM, None) + res.assert_task_error(ErrorDomain.ELEMENT, None) + + # Sources are not pushed as the build queue is before the source push + # queue. + assert "Pushed source " not in res.stderr |