summaryrefslogtreecommitdiff
path: root/tests/frontend/track.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-19 17:31:17 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-03-20 18:29:14 +0900
commit2bcae91f1e26d8396023425dce34b55a7e4095e5 (patch)
treeb4ccd5cd6ecfbc7e8496de36672e4df6639d63ce /tests/frontend/track.py
parent150c7441279513249c10d10f12f06a0a5d8ab768 (diff)
downloadbuildstream-2bcae91f1e26d8396023425dce34b55a7e4095e5.tar.gz
tests/frontend/track.py: Test tracking with optionality
Tests that `bst track` sets the ref in the expected node if the node containing the ref is conditionalized with a project option. This tests both the regular inline behavior, and also the project.refs behavior.
Diffstat (limited to 'tests/frontend/track.py')
-rw-r--r--tests/frontend/track.py60
1 files changed, 56 insertions, 4 deletions
diff --git a/tests/frontend/track.py b/tests/frontend/track.py
index 138616fbf..d007a8b77 100644
--- a/tests/frontend/track.py
+++ b/tests/frontend/track.py
@@ -5,10 +5,8 @@ from tests.testutils import cli, create_repo, ALL_REPO_KINDS
from buildstream import _yaml
# Project directory
-DATA_DIR = os.path.join(
- os.path.dirname(os.path.realpath(__file__)),
- "project",
-)
+TOP_DIR = os.path.dirname(os.path.realpath(__file__))
+DATA_DIR = os.path.join(TOP_DIR, 'project')
def generate_element(repo, element_path, dep_name=None):
@@ -163,3 +161,57 @@ def test_track_recurse_except(cli, tmpdir, datafiles, kind):
# Assert that the dependency is buildable and the target is waiting
assert cli.get_element_state(project, element_dep_name) == 'no reference'
assert cli.get_element_state(project, element_target_name) == 'waiting'
+
+
+@pytest.mark.datafiles(os.path.join(TOP_DIR))
+@pytest.mark.parametrize("ref_storage", [('inline'), ('project-refs')])
+def test_track_optional(cli, tmpdir, datafiles, ref_storage):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'track-optional-' + ref_storage)
+ dev_files_path = os.path.join(project, 'files')
+ element_path = os.path.join(project, 'target.bst')
+
+ # Create our repo object of the given source type with
+ # the dev files, and then collect the initial ref.
+ #
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(dev_files_path)
+
+ # Now create an optional test branch and add a commit to that,
+ # so two branches with different heads now exist.
+ #
+ repo.branch('test')
+ repo.add_commit()
+
+ # Substitute the {repo} for the git repo we created
+ with open(element_path) as f:
+ target_bst = f.read()
+ target_bst = target_bst.format(repo=repo.repo)
+ with open(element_path, 'w') as f:
+ f.write(target_bst)
+
+ # First track for both options
+ #
+ # We want to track and persist the ref separately in this test
+ #
+ result = cli.run(project=project, args=['--option', 'test', 'False', 'track', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['--option', 'test', 'True', 'track', 'target.bst'])
+ result.assert_success()
+
+ # Now fetch the key for both options
+ #
+ result = cli.run(project=project, args=[
+ '--option', 'test', 'False', 'show', '--deps', 'none', '--format', '%{key}', 'target.bst'
+ ])
+ result.assert_success()
+ master_key = result.output
+
+ result = cli.run(project=project, args=[
+ '--option', 'test', 'True', 'show', '--deps', 'none', '--format', '%{key}', 'target.bst'
+ ])
+ result.assert_success()
+ test_key = result.output
+
+ # Assert that the keys are different when having
+ # tracked separate branches
+ assert test_key != master_key