diff --git a/tests/integration/example.test.env.yaml b/tests/integration/example.test.env.yaml index 6666a123..16636cb3 100644 --- a/tests/integration/example.test.env.yaml +++ b/tests/integration/example.test.env.yaml @@ -88,3 +88,6 @@ testdata: # For this scenario reusing former builds doesn't make sense. module: testmodule2 branch: test-stream-expans-branch + buildrequire_invalid_module: + module: testmodule + branch: test-buildrequire-invalid-module diff --git a/tests/integration/test_buildrequire_invalid_module.py b/tests/integration/test_buildrequire_invalid_module.py new file mode 100644 index 00000000..cf06af35 --- /dev/null +++ b/tests/integration/test_buildrequire_invalid_module.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# SPDX-License-Identifier: MIT +import pytest +from sh import ErrorReturnCode + + +def test_buildrequire_invalid_module(pkg_util, scenario, repo, koji): + """ + Run a build with with an invalid 'build_require' module. + I.e.: required module is picked in such a way, + that it is not tagged according to the the base module (platform) requirements, + see platform's modulemd file and its 'koji_tag_with_modules' attribute + (e.g.: platform: el-8.1.0 --> rhel-8.1.0-modules-build). + + Koji resolver is expected to not be able to satisfy this build requirement + and hence fail the build. + + Assert that: + * the module build hasn't been accepted by MBS: + rhpkg utility returns something else than 0 + * "Cannot find any module build..." found on STDERR + + If assert fails: + * cancel all triggered module builds. + + """ + + repo.bump() + + expected_error = "Cannot find any module builds" + with pytest.raises(ErrorReturnCode) as excinfo: + # Override 'baked' (_err=sys.stderr) stderr redirect: + # Here we are fine with what plain sh.Command gives us + # (otherwise ErrorReturnCode.stderr is incomplete). + builds = pkg_util.run("--optional", "rebuild_strategy=all", _err=None) + try: + for build in builds: + print("Canceling module-build {}...".format(build.id)) + pkg_util.cancel(build) + except ErrorReturnCode: + # Do nothing, this is just a clean-up of accidentally started builds + # in case that the test-case fails + pass + assert expected_error in excinfo.value.stderr.decode("utf-8") diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 480db8a9..62dcbc00 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -167,11 +167,13 @@ class PackagingUtility: def __init__(self, packaging_utility, mbs_api): self._packaging_utility = Command(packaging_utility).bake( - _out=sys.stdout, _err=sys.stderr, _tee=True + _out=sys.stdout, + _err=sys.stderr, + _tee=True ) self._mbs_api = mbs_api - def run(self, *args, reuse=None): + def run(self, *args, reuse=None, **kwargs): """Run one or more module builds :param args: Options and arguments for the build command @@ -191,7 +193,7 @@ class PackagingUtility: else: build_ids = [reuse] else: - stdout = self._packaging_utility("module-build", *args).stdout.decode("utf-8") + stdout = self._packaging_utility("module-build", *args, **kwargs).stdout.decode("utf-8") build_ids = re.findall(self._mbs_api + r"module-builds/(\d+)", stdout) return [Build(self._mbs_api, int(build_id)) for build_id in build_ids]