diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-05 21:18:48 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-05 22:14:32 +0900 |
commit | abb9ef2220afdc8466d0f6448787a0f8d87e5918 (patch) | |
tree | 8f0b8c6fdfbf57975a4db852781edc49d658363d | |
parent | 50af604e51c3cc325d7bbc60185b13d72c9fe634 (diff) | |
download | buildstream-abb9ef2220afdc8466d0f6448787a0f8d87e5918.tar.gz |
tests/frontend/show.py: Test behaviors of showing junctioned elements
o Test error conditions for showing an unfetched junctioned project
o Test error conditions for showing an untracked junctioned project
Both tests check both modes of ref-storage.
This adds a new shared helper function `generate_junction`
-rw-r--r-- | tests/frontend/__init__.py | 34 | ||||
-rw-r--r-- | tests/frontend/project/files/sub-project/elements/import-etc.bst | 4 | ||||
-rw-r--r-- | tests/frontend/project/files/sub-project/files/etc-files/etc/animal.conf | 1 | ||||
-rw-r--r-- | tests/frontend/project/files/sub-project/project.conf | 4 | ||||
-rw-r--r-- | tests/frontend/show.py | 93 |
5 files changed, 135 insertions, 1 deletions
diff --git a/tests/frontend/__init__.py b/tests/frontend/__init__.py index 8cf7625a9..2eadf1519 100644 --- a/tests/frontend/__init__.py +++ b/tests/frontend/__init__.py @@ -1,4 +1,5 @@ import os +from tests.testutils import create_repo from buildstream import _yaml @@ -8,3 +9,36 @@ def configure_project(path, config): config['name'] = 'test' config['element-path'] = 'elements' _yaml.dump(config, os.path.join(path, 'project.conf')) + + +# generate_junction() +# +# Generates a junction element with a git repository +# +# Args: +# tmpdir: The tmpdir fixture, for storing the generated git repo +# subproject_path: The path for the subproject, to add to the git repo +# junction_path: The location to store the generated junction element +# store_ref: Whether to store the ref in the junction.bst file +# +# Returns: +# (str): The ref +# +def generate_junction(tmpdir, subproject_path, junction_path, *, store_ref=True): + # Create a repo to hold the subproject and generate + # a junction element for it + # + repo = create_repo('git', str(tmpdir)) + source_ref = ref = repo.create(subproject_path) + if not store_ref: + source_ref = None + + element = { + 'kind': 'junction', + 'sources': [ + repo.source_config(ref=source_ref) + ] + } + _yaml.dump(element, junction_path) + + return ref diff --git a/tests/frontend/project/files/sub-project/elements/import-etc.bst b/tests/frontend/project/files/sub-project/elements/import-etc.bst new file mode 100644 index 000000000..f0171990e --- /dev/null +++ b/tests/frontend/project/files/sub-project/elements/import-etc.bst @@ -0,0 +1,4 @@ +kind: import +sources: +- kind: local + path: files/etc-files diff --git a/tests/frontend/project/files/sub-project/files/etc-files/etc/animal.conf b/tests/frontend/project/files/sub-project/files/etc-files/etc/animal.conf new file mode 100644 index 000000000..db8c36cba --- /dev/null +++ b/tests/frontend/project/files/sub-project/files/etc-files/etc/animal.conf @@ -0,0 +1 @@ +animal=Pony diff --git a/tests/frontend/project/files/sub-project/project.conf b/tests/frontend/project/files/sub-project/project.conf new file mode 100644 index 000000000..bbb8414a3 --- /dev/null +++ b/tests/frontend/project/files/sub-project/project.conf @@ -0,0 +1,4 @@ +# Project config for frontend build test +name: subtest + +element-path: elements diff --git a/tests/frontend/show.py b/tests/frontend/show.py index fda5214bf..16abe5f40 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -1,7 +1,12 @@ import os import pytest import itertools -from tests.testutils.runcli import cli +from tests.testutils import cli + +from buildstream import _yaml +from buildstream._exceptions import ErrorDomain, LoadErrorReason + +from . import configure_project, generate_junction # Project directory DATA_DIR = os.path.join( @@ -104,3 +109,89 @@ def test_target_is_dependency(cli, tmpdir, datafiles): names = [name[len('multiple_targets/dependency/'):] for name in names] assert names == ['pony.bst', 'horsey.bst', 'zebry.bst'] + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')]) +def test_unfetched_junction(cli, tmpdir, datafiles, ref_storage): + project = os.path.join(datafiles.dirname, datafiles.basename) + subproject_path = os.path.join(project, 'files', 'sub-project') + junction_path = os.path.join(project, 'elements', 'junction.bst') + element_path = os.path.join(project, 'elements', 'junction-dep.bst') + + configure_project(project, { + 'ref-storage': ref_storage + }) + + # Create a repo to hold the subproject and generate a junction element for it + ref = generate_junction(tmpdir, subproject_path, junction_path, store_ref=(ref_storage == 'inline')) + + # Create a stack element to depend on a cross junction element + # + element = { + 'kind': 'stack', + 'depends': [ + { + 'junction': 'junction.bst', + 'filename': 'import-etc.bst' + } + ] + } + _yaml.dump(element, element_path) + + # Dump a project.refs if we're using project.refs storage + # + if ref_storage == 'project.refs': + project_refs = { + 'projects': { + 'test': { + 'junction.bst': [ + { + 'ref': ref + } + ] + } + } + } + _yaml.dump(project_refs, os.path.join(project, 'project.refs')) + + # Assert the correct error when trying to show the pipeline + result = cli.run(project=project, silent=True, args=[ + 'show', 'junction-dep.bst']) + + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_FETCH_NEEDED) + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')]) +def test_inconsistent_junction(cli, tmpdir, datafiles, ref_storage): + project = os.path.join(datafiles.dirname, datafiles.basename) + subproject_path = os.path.join(project, 'files', 'sub-project') + junction_path = os.path.join(project, 'elements', 'junction.bst') + element_path = os.path.join(project, 'elements', 'junction-dep.bst') + + configure_project(project, { + 'ref-storage': ref_storage + }) + + # Create a repo to hold the subproject and generate a junction element for it + generate_junction(tmpdir, subproject_path, junction_path, store_ref=False) + + # Create a stack element to depend on a cross junction element + # + element = { + 'kind': 'stack', + 'depends': [ + { + 'junction': 'junction.bst', + 'filename': 'import-etc.bst' + } + ] + } + _yaml.dump(element, element_path) + + # Assert the correct error when trying to show the pipeline + result = cli.run(project=project, silent=True, args=[ + 'show', 'junction-dep.bst']) + + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_INCONSISTENT) |