From 60d5e070c17ef15caa42a847b0f9957432bd6468 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Sat, 6 Jan 2018 18:39:05 +0900 Subject: tests/pipeline/preflight.py: Added test to ensure graceful exit at preflight error time --- tests/pipeline/preflight-error/error.bst | 4 +++ .../preflight-error/errorplugin/__init__.py | 0 .../preflight-error/errorplugin/preflighterror.py | 35 ++++++++++++++++++++++ tests/pipeline/preflight-error/project.conf | 11 +++++++ tests/pipeline/preflight.py | 19 ++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 tests/pipeline/preflight-error/error.bst create mode 100644 tests/pipeline/preflight-error/errorplugin/__init__.py create mode 100644 tests/pipeline/preflight-error/errorplugin/preflighterror.py create mode 100644 tests/pipeline/preflight-error/project.conf create mode 100644 tests/pipeline/preflight.py diff --git a/tests/pipeline/preflight-error/error.bst b/tests/pipeline/preflight-error/error.bst new file mode 100644 index 000000000..a9772770c --- /dev/null +++ b/tests/pipeline/preflight-error/error.bst @@ -0,0 +1,4 @@ +kind: import +description: An element with a failing source at preflight time +sources: +- kind: preflighterror diff --git a/tests/pipeline/preflight-error/errorplugin/__init__.py b/tests/pipeline/preflight-error/errorplugin/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/pipeline/preflight-error/errorplugin/preflighterror.py b/tests/pipeline/preflight-error/errorplugin/preflighterror.py new file mode 100644 index 000000000..59c49e012 --- /dev/null +++ b/tests/pipeline/preflight-error/errorplugin/preflighterror.py @@ -0,0 +1,35 @@ +from buildstream import Source, SourceError, Consistency + + +class PreflightErrorSource(Source): + + def configure(self, node): + pass + + def preflight(self): + + # Raise a preflight error unconditionally + raise SourceError("{}: Unsatisfied requirements in preflight, raising this error", + reason="the-preflight-error") + + def get_unique_key(self): + return {} + + def get_consistency(self): + return Consistency.CACHED + + def get_ref(self): + return None + + def set_ref(self, ref, node): + pass + + def fetch(self): + pass + + def stage(self, directory): + pass + + +def setup(): + return PreflightErrorSource diff --git a/tests/pipeline/preflight-error/project.conf b/tests/pipeline/preflight-error/project.conf new file mode 100644 index 000000000..20a234413 --- /dev/null +++ b/tests/pipeline/preflight-error/project.conf @@ -0,0 +1,11 @@ +# Basic project configuration that doesnt override anything +# +name: pony + +# Whitelist the local test Source "errorplugin" to be loaded +# +plugins: +- origin: local + path: errorplugin + sources: + preflighterror: 0 diff --git a/tests/pipeline/preflight.py b/tests/pipeline/preflight.py new file mode 100644 index 000000000..f9eb649ff --- /dev/null +++ b/tests/pipeline/preflight.py @@ -0,0 +1,19 @@ +import os +import pytest + +from buildstream._exceptions import ErrorDomain +from tests.testutils.runcli import cli + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'preflight-error', +) + + +@pytest.mark.datafiles(DATA_DIR) +def test_load_simple(cli, datafiles, tmpdir): + basedir = os.path.join(datafiles.dirname, datafiles.basename) + + # Lets try to fetch it... + result = cli.run(project=basedir, args=['fetch', 'error.bst']) + result.assert_main_error(ErrorDomain.PIPELINE, "the-preflight-error") -- cgit v1.2.1