summaryrefslogtreecommitdiff
path: root/tests/frontend
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-08-07 10:50:55 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-08-14 14:36:51 +0000
commit940a4bbe69e59e9e7568348dffa6c0075d48d69a (patch)
treea9f509316629d04d15e32f37378dad064af8ab83 /tests/frontend
parentb1b9d60b85ca0b6af06a1faac3a4380da372883c (diff)
downloadbuildstream-940a4bbe69e59e9e7568348dffa6c0075d48d69a.tar.gz
_stream.py: Ensure push does not fail if artifact not cachedjennis/push_unbuilt_artifact
A test for this has also been added to tests/frontend/push.py
Diffstat (limited to 'tests/frontend')
-rw-r--r--tests/frontend/push.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index 93b7425b2..e92646154 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -98,6 +98,91 @@ def test_push(cli, tmpdir, datafiles):
assert_shared(cli, share1, project, 'target.bst')
assert_shared(cli, share2, project, 'target.bst')
+# Tests that:
+#
+# * `bst artifact push` fails if the element is not cached locally
+# * `bst artifact push` fails if multiple elements are not cached locally
+#
+@pytest.mark.datafiles(DATA_DIR)
+def test_push_fails(cli, tmpdir, datafiles):
+ project = str(datafiles)
+
+ # Set up the share
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
+ # Configure bst to be able to push to the share
+ cli.configure({
+ 'artifacts': [
+ {'url': share.repo, 'push': True},
+ ]
+ })
+
+ # First ensure that the target is *NOT* cache
+ assert cli.get_element_state(project, 'target.bst') != 'cached'
+
+ # Now try and push the target
+ result = cli.run(project=project, args=['artifact', 'push', 'target.bst'])
+ result.assert_main_error(ErrorDomain.STREAM, None)
+
+ assert "Push failed: target.bst is not cached" in result.stderr
+
+ # Now ensure that deps are also not cached
+ assert cli.get_element_state(project, 'import-bin.bst') != 'cached'
+ assert cli.get_element_state(project, 'import-dev.bst') != 'cached'
+ assert cli.get_element_state(project, 'compose-all.bst') != 'cached'
+
+
+# Tests that:
+#
+# * `bst artifact push` fails when one of the targets is not cached, but still pushes the others
+#
+@pytest.mark.datafiles(DATA_DIR)
+def test_push_fails_with_on_error_continue(cli, tmpdir, datafiles):
+ project = str(datafiles)
+
+ # Set up the share
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
+
+ # First build the target (and its deps)
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ assert cli.get_element_state(project, 'target.bst') == 'cached'
+ assert cli.get_element_state(project, 'import-dev.bst') == 'cached'
+
+ # Now delete the artifact of a dependency and ensure it is not in the cache
+ result = cli.run(project=project, args=['artifact', 'delete', 'import-dev.bst'])
+ assert cli.get_element_state(project, 'import-dev.bst') != 'cached'
+
+ # Configure bst to be able to push to the share
+ cli.configure({
+ 'artifacts': [
+ {'url': share.repo, 'push': True},
+ ]
+ })
+
+ # Now try and push the target with its deps using --on-error continue
+ # and assert that push failed, but what could be pushed was pushed
+ result = cli.run(project=project,
+ args=['--on-error=continue', 'artifact', 'push', '--deps', 'all', 'target.bst'])
+
+ # The overall process should return as failed
+ result.assert_main_error(ErrorDomain.STREAM, None)
+
+ # We should still have pushed what we could
+ assert_shared(cli, share, project, 'import-bin.bst')
+ assert_shared(cli, share, project, 'compose-all.bst')
+ assert_shared(cli, share, project, 'target.bst')
+
+ assert_not_shared(cli, share, project, 'import-dev.bst')
+ errors = [
+ "import-dev.bst is not cached",
+ (
+ "Error while pushing. The following elements were not pushed as they are not yet cached:\n"
+ "\n"
+ "\timport-dev.bst\n"
+ )
+ ]
+ for error in errors:
+ assert error in result.stderr
+
# Tests that `bst artifact push --deps all` pushes all dependencies of the given element.
#