diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-19 17:31:17 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-03-20 18:29:14 +0900 |
commit | 2bcae91f1e26d8396023425dce34b55a7e4095e5 (patch) | |
tree | b4ccd5cd6ecfbc7e8496de36672e4df6639d63ce /tests | |
parent | 150c7441279513249c10d10f12f06a0a5d8ab768 (diff) | |
download | buildstream-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')
8 files changed, 132 insertions, 4 deletions
diff --git a/tests/frontend/track-optional-inline/files/usr/include/pony.h b/tests/frontend/track-optional-inline/files/usr/include/pony.h new file mode 100644 index 000000000..40bd0c2e7 --- /dev/null +++ b/tests/frontend/track-optional-inline/files/usr/include/pony.h @@ -0,0 +1,12 @@ +#ifndef __PONY_H__ +#define __PONY_H__ + +#define PONY_BEGIN "Once upon a time, there was a pony." +#define PONY_END "And they lived happily ever after, the end." + +#define MAKE_PONY(story) \ + PONY_BEGIN \ + story \ + PONY_END + +#endif /* __PONY_H__ */ diff --git a/tests/frontend/track-optional-inline/project.conf b/tests/frontend/track-optional-inline/project.conf new file mode 100644 index 000000000..3f02c4718 --- /dev/null +++ b/tests/frontend/track-optional-inline/project.conf @@ -0,0 +1,7 @@ +name: test + +options: + test: + type: bool + description: Test boolean + default: False diff --git a/tests/frontend/track-optional-inline/target.bst b/tests/frontend/track-optional-inline/target.bst new file mode 100644 index 000000000..36b040840 --- /dev/null +++ b/tests/frontend/track-optional-inline/target.bst @@ -0,0 +1,15 @@ +# Optionally track the test branch +# +kind: import + +(?): +- test: + sources: + - kind: git + url: file://{repo} + track: test +- not test: + sources: + - kind: git + url: file://{repo} + track: master diff --git a/tests/frontend/track-optional-project-refs/files/usr/include/pony.h b/tests/frontend/track-optional-project-refs/files/usr/include/pony.h new file mode 100644 index 000000000..40bd0c2e7 --- /dev/null +++ b/tests/frontend/track-optional-project-refs/files/usr/include/pony.h @@ -0,0 +1,12 @@ +#ifndef __PONY_H__ +#define __PONY_H__ + +#define PONY_BEGIN "Once upon a time, there was a pony." +#define PONY_END "And they lived happily ever after, the end." + +#define MAKE_PONY(story) \ + PONY_BEGIN \ + story \ + PONY_END + +#endif /* __PONY_H__ */ diff --git a/tests/frontend/track-optional-project-refs/project.conf b/tests/frontend/track-optional-project-refs/project.conf new file mode 100644 index 000000000..37fe02caa --- /dev/null +++ b/tests/frontend/track-optional-project-refs/project.conf @@ -0,0 +1,9 @@ +name: test + +ref-storage: project.refs + +options: + test: + type: bool + description: Test boolean + default: False diff --git a/tests/frontend/track-optional-project-refs/project.refs b/tests/frontend/track-optional-project-refs/project.refs new file mode 100644 index 000000000..c9af5e03b --- /dev/null +++ b/tests/frontend/track-optional-project-refs/project.refs @@ -0,0 +1,9 @@ +projects: + test: + (?): + - test: + target.bst: + - ref: '' + - not test: + target.bst: + - ref: '' diff --git a/tests/frontend/track-optional-project-refs/target.bst b/tests/frontend/track-optional-project-refs/target.bst new file mode 100644 index 000000000..77a039a66 --- /dev/null +++ b/tests/frontend/track-optional-project-refs/target.bst @@ -0,0 +1,12 @@ +# Optionally track the test branch +# +kind: import + +sources: +- kind: git + url: file://{repo} + (?): + - test: + track: test + - not test: + track: master 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 |