Commit abb9ef22 authored by Tristan Van Berkom's avatar Tristan Van Berkom

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`
parent 50af604e
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
kind: import
sources:
- kind: local
path: files/etc-files
# Project config for frontend build test
name: subtest
element-path: elements
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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment