summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTom Pollard <tom.pollard@codethink.co.uk>2019-01-30 16:18:17 +0000
committerTom Pollard <tom.pollard@codethink.co.uk>2019-02-05 11:22:01 +0000
commitcd8e5e272fef36358f1e36885d7db69ee5f97dc2 (patch)
treec612a1a7f47b82399c3ddabdbf2b10694f80aa0a /tests
parent3ab096510186842afb90c16a1c1bb7e58035265f (diff)
downloadbuildstream-cd8e5e272fef36358f1e36885d7db69ee5f97dc2.tar.gz
Add --remote, -r option to bst build, inline with pull & push
Providing a remote will limit build's pull/push remote actions to the given remote specifically, ignoring those defined via user or project configuration.
Diffstat (limited to 'tests')
-rw-r--r--tests/frontend/completions.py3
-rw-r--r--tests/frontend/pull.py53
-rw-r--r--tests/frontend/push.py30
3 files changed, 85 insertions, 1 deletions
diff --git a/tests/frontend/completions.py b/tests/frontend/completions.py
index 007064f89..93b908f60 100644
--- a/tests/frontend/completions.py
+++ b/tests/frontend/completions.py
@@ -141,7 +141,8 @@ def test_commands(cli, cmd, word_idx, expected):
('bst --no-colors build -', 3, ['--all ', '--track ', '--track-all ',
'--track-except ',
'--track-cross-junctions ', '-J ',
- '--track-save ']),
+ '--track-save ',
+ '--remote ', '-r ']),
# Test the behavior of completing after an option that has a
# parameter that cannot be completed, vs an option that has
diff --git a/tests/frontend/pull.py b/tests/frontend/pull.py
index 20b740948..a2c710fb8 100644
--- a/tests/frontend/pull.py
+++ b/tests/frontend/pull.py
@@ -408,3 +408,56 @@ def test_pull_missing_notifies_user(caplog, cli, tmpdir, datafiles):
assert "INFO Remote ({}) does not have".format(share.repo) in result.stderr
assert "SKIPPED Pull" in result.stderr
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_remote_option(caplog, cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ caplog.set_level(1)
+
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare1')) as shareuser,\
+ create_artifact_share(os.path.join(str(tmpdir), 'artifactshare2')) as shareproject,\
+ create_artifact_share(os.path.join(str(tmpdir), 'artifactshare3')) as sharecli:
+
+ # Add shareproject repo url to project.conf
+ with open(os.path.join(project, "project.conf"), "a") as projconf:
+ projconf.write("artifacts:\n url: {}\n push: True".format(shareproject.repo))
+
+ # Configure shareuser remote in user conf
+ cli.configure({
+ 'artifacts': {'url': shareuser.repo, 'push': True}
+ })
+
+ # Push the artifacts to the shareuser and shareproject remotes.
+ # Assert that shareuser and shareproject have the artfifacts cached,
+ # but sharecli doesn't, then delete locally cached elements
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ all_elements = ['target.bst', 'import-bin.bst', 'compose-all.bst']
+ for element_name in all_elements:
+ assert element_name in result.get_pushed_elements()
+ assert_not_shared(cli, sharecli, project, element_name)
+ assert_shared(cli, shareuser, project, element_name)
+ assert_shared(cli, shareproject, project, element_name)
+ cli.remove_artifact_from_cache(project, element_name)
+
+ # Now check that a build with cli set as sharecli results in nothing being pulled,
+ # as it doesn't have them cached and shareuser/shareproject should be ignored. This
+ # will however result in the artifacts being built and pushed to it
+ result = cli.run(project=project, args=['build', '--remote', sharecli.repo, 'target.bst'])
+ result.assert_success()
+ for element_name in all_elements:
+ assert element_name not in result.get_pulled_elements()
+ assert_shared(cli, sharecli, project, element_name)
+ cli.remove_artifact_from_cache(project, element_name)
+
+ # Now check that a clean build with cli set as sharecli should result in artifacts only
+ # being pulled from it, as that was provided via the cli and is populated
+ result = cli.run(project=project, args=['build', '--remote', sharecli.repo, 'target.bst'])
+ result.assert_success()
+ for element_name in all_elements:
+ assert cli.get_element_state(project, element_name) == 'cached'
+ assert element_name in result.get_pulled_elements()
+ assert shareproject.repo not in result.stderr
+ assert shareuser.repo not in result.stderr
+ assert sharecli.repo in result.stderr
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index f3f9b52f1..729df9ae9 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -416,3 +416,33 @@ def test_push_already_cached(caplog, cli, tmpdir, datafiles):
assert not result.get_pushed_elements(), "No elements should have been pushed since the cache was populated"
assert "INFO Remote ({}) already has ".format(share.repo) in result.stderr
assert "SKIPPED Push" in result.stderr
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_remote_option(caplog, cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ caplog.set_level(1)
+
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare1')) as shareuser,\
+ create_artifact_share(os.path.join(str(tmpdir), 'artifactshare2')) as shareproject,\
+ create_artifact_share(os.path.join(str(tmpdir), 'artifactshare3')) as sharecli:
+
+ # Add shareproject repo url to project.conf
+ with open(os.path.join(project, "project.conf"), "a") as projconf:
+ projconf.write("artifacts:\n url: {}\n push: True".format(shareproject.repo))
+
+ # Configure shareuser remote in user conf
+ cli.configure({
+ 'artifacts': {'url': shareuser.repo, 'push': True}
+ })
+
+ result = cli.run(project=project, args=['build', '--remote', sharecli.repo, 'target.bst'])
+
+ # Artifacts should have only been pushed to sharecli, as that was provided via the cli
+ result.assert_success()
+ all_elements = ['target.bst', 'import-bin.bst', 'compose-all.bst']
+ for element_name in all_elements:
+ assert element_name in result.get_pushed_elements()
+ assert_shared(cli, sharecli, project, element_name)
+ assert_not_shared(cli, shareuser, project, element_name)
+ assert_not_shared(cli, shareproject, project, element_name)