diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-01 13:24:12 -0400 |
---|---|---|
committer | Benjamin Schubert <bschubert15@bloomberg.net> | 2018-11-08 10:21:12 +0000 |
commit | c51ba01b7dce07c713ba7d9fd5505a5b9d575c5b (patch) | |
tree | 8c74ffd7e3d6cba52b895cd191248d1c91dab769 /tests/sandboxes | |
parent | cf2e0059880058f0672aebb38f57fc43d347ae9a (diff) | |
download | buildstream-c51ba01b7dce07c713ba7d9fd5505a5b9d575c5b.tar.gz |
Test that helpful messages are raised when missing dependencies
This adds a `reason` to the SandboxEror thrown in sandboxdummy
to be able to understand where the error comes from
Diffstat (limited to 'tests/sandboxes')
4 files changed, 95 insertions, 0 deletions
diff --git a/tests/sandboxes/missing-dependencies/elements/base.bst b/tests/sandboxes/missing-dependencies/elements/base.bst new file mode 100755 index 000000000..dcd6a9d60 --- /dev/null +++ b/tests/sandboxes/missing-dependencies/elements/base.bst @@ -0,0 +1,4 @@ +kind: import +sources: +- kind: local + path: files/base/ diff --git a/tests/sandboxes/missing-dependencies/files/base/bin/sh b/tests/sandboxes/missing-dependencies/files/base/bin/sh new file mode 100755 index 000000000..c102e04c1 --- /dev/null +++ b/tests/sandboxes/missing-dependencies/files/base/bin/sh @@ -0,0 +1 @@ +# This is the original bash diff --git a/tests/sandboxes/missing-dependencies/project.conf b/tests/sandboxes/missing-dependencies/project.conf new file mode 100755 index 000000000..080ab758f --- /dev/null +++ b/tests/sandboxes/missing-dependencies/project.conf @@ -0,0 +1,4 @@ +# Project config for missing dependencies test +name: test + +element-path: elements diff --git a/tests/sandboxes/missing_dependencies.py b/tests/sandboxes/missing_dependencies.py new file mode 100644 index 000000000..d77674c64 --- /dev/null +++ b/tests/sandboxes/missing_dependencies.py @@ -0,0 +1,86 @@ +import os +import pytest +from tests.testutils import cli +from tests.testutils.site import IS_LINUX + +from buildstream import _yaml +from buildstream._exceptions import ErrorDomain + + +# Project directory +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "missing-dependencies", +) + + +@pytest.mark.skipif(not IS_LINUX, reason='Only available on Linux') +@pytest.mark.datafiles(DATA_DIR) +def test_missing_brwap_has_nice_error_message(cli, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + element_path = os.path.join(project, 'elements', 'element.bst') + + # Write out our test target + element = { + 'kind': 'script', + 'depends': [ + { + 'filename': 'base.bst', + 'type': 'build', + }, + ], + 'config': { + 'commands': [ + 'false', + ], + }, + } + _yaml.dump(element, element_path) + + # Build without access to host tools, this should fail with a nice error + result = cli.run( + project=project, args=['build', 'element.bst'], env={'PATH': ''}) + result.assert_task_error(ErrorDomain.SANDBOX, 'unavailable-local-sandbox') + assert "not found" in result.stderr + + +@pytest.mark.skipif(not IS_LINUX, reason='Only available on Linux') +@pytest.mark.datafiles(DATA_DIR) +def test_old_brwap_has_nice_error_message(cli, datafiles, tmp_path): + bwrap = tmp_path.joinpath('bin/bwrap') + bwrap.parent.mkdir() + with bwrap.open('w') as fp: + fp.write(''' + #!/bin/sh + echo bubblewrap 0.0.1 + '''.strip()) + + bwrap.chmod(0o755) + + project = os.path.join(datafiles.dirname, datafiles.basename) + element_path = os.path.join(project, 'elements', 'element3.bst') + + # Write out our test target + element = { + 'kind': 'script', + 'depends': [ + { + 'filename': 'base.bst', + 'type': 'build', + }, + ], + 'config': { + 'commands': [ + 'false', + ], + }, + } + _yaml.dump(element, element_path) + + # Build without access to host tools, this should fail with a nice error + result = cli.run( + project=project, + args=['--debug', '--verbose', 'build', 'element3.bst'], + env={'PATH': str(tmp_path.joinpath('bin'))}) + result.assert_task_error(ErrorDomain.SANDBOX, 'unavailable-local-sandbox') + assert "too old" in result.stderr |