diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-01-06 18:39:05 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-01-06 19:26:43 +0900 |
commit | d35896e1897329d4715ba65a25074f6710bbf765 (patch) | |
tree | 64fb66a13295292f5f348b6df4a7f6e64b0fac73 | |
parent | f1183059abac95ba1f90a54ba02b69326cefe84d (diff) | |
download | buildstream-d35896e1897329d4715ba65a25074f6710bbf765.tar.gz |
tests/pipeline/preflight.py: Added test to ensure graceful exit at preflight error timefix-preflight-errors
-rw-r--r-- | tests/pipeline/preflight-error/error.bst | 4 | ||||
-rw-r--r-- | tests/pipeline/preflight-error/errorplugin/__init__.py | 0 | ||||
-rw-r--r-- | tests/pipeline/preflight-error/errorplugin/preflighterror.py | 35 | ||||
-rw-r--r-- | tests/pipeline/preflight-error/project.conf | 11 | ||||
-rw-r--r-- | tests/pipeline/preflight.py | 19 |
5 files changed, 69 insertions, 0 deletions
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 --- /dev/null +++ b/tests/pipeline/preflight-error/errorplugin/__init__.py 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") |