summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-08-16 16:51:50 +0100
committerJames Ennis <james.ennis@codethink.co.uk>2019-08-22 16:35:30 +0100
commitd5c1213928f29f71a52271d485ac2a83603e4b6d (patch)
treeb702d5726d85c90b6ba460a8a73eaadd3a4257bb
parent1a84374cec892463db74d1c35f58de53b29605b7 (diff)
downloadbuildstream-jennis/load_artifact_dependencies.tar.gz
tests/frontend/artifact.py: test artifact delete with --deps optionsjennis/load_artifact_dependencies
-rw-r--r--tests/frontend/artifact.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/frontend/artifact.py b/tests/frontend/artifact.py
index fed0b1aaa..f48807ef6 100644
--- a/tests/frontend/artifact.py
+++ b/tests/frontend/artifact.py
@@ -24,7 +24,9 @@
import os
import pytest
+from buildstream.element import _get_normal_name
from buildstream.testing import cli # pylint: disable=unused-import
+from buildstream._exceptions import ErrorDomain
from tests.testutils import create_artifact_share
@@ -278,3 +280,92 @@ def test_artifact_delete_pulled_artifact_without_buildtree(cli, tmpdir, datafile
result = cli.run(project=project, args=['artifact', 'delete', element])
result.assert_success()
assert cli.get_element_state(project, element) != 'cached'
+
+
+# Test that we can delete the build deps of an element
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_delete_elements_build_deps(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+
+ # Build the element and ensure it's cached
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ # Assert element and build deps are cached
+ assert cli.get_element_state(project, element) == 'cached'
+ bdep_states = cli.get_element_states(project, [element], deps='build')
+ for state in bdep_states.values():
+ assert state == 'cached'
+
+ result = cli.run(project=project, args=['artifact', 'delete', '--deps', 'build', element])
+ result.assert_success()
+
+ # Assert that the build deps have been deleted and that the artifact remains cached
+ assert cli.get_element_state(project, element) == 'cached'
+ bdep_states = cli.get_element_states(project, [element], deps='build')
+ for state in bdep_states.values():
+ assert state != 'cached'
+
+
+# Test that we can delete the build deps of an artifact by providing an artifact ref
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_delete_artifacts_build_deps(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+
+ # Configure a local cache
+ local_cache = os.path.join(str(tmpdir), 'cache')
+ cli.configure({'cachedir': local_cache})
+
+ # First build an element so that we can find its artifact
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ # Obtain the artifact ref
+ cache_key = cli.get_element_key(project, element)
+ artifact = os.path.join('test', os.path.splitext(element)[0], cache_key)
+
+ # Explicitly check that the ARTIFACT exists in the cache
+ assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact))
+
+ # get the artifact refs of the build dependencies
+ bdep_refs = []
+ bdep_states = cli.get_element_states(project, [element], deps='build')
+ for bdep in bdep_states.keys():
+ bdep_refs.append(os.path.join('test', _get_normal_name(bdep), cli.get_element_key(project, bdep)))
+
+ # Assert build dependencies are cached
+ for ref in bdep_refs:
+ assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', ref))
+
+ # Delete the artifact
+ result = cli.run(project=project, args=['artifact', 'delete', '--deps', 'build', artifact])
+ result.assert_success()
+
+ # Check that the artifact's build deps are no longer in the cache
+ # Assert build dependencies have been deleted and that the artifact remains
+ for ref in bdep_refs:
+ assert not os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', ref))
+ assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact))
+
+
+# Test that `--deps all` option fails if an artifact ref is specified
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_delete_artifact_with_deps_all_fails(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+
+ # First build an element so that we can find its artifact
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ # Obtain the artifact ref
+ cache_key = cli.get_element_key(project, element)
+ artifact = os.path.join('test', os.path.splitext(element)[0], cache_key)
+
+ # Try to delete the artifact with all of its dependencies
+ result = cli.run(project=project, args=['artifact', 'delete', '--deps', 'all', artifact])
+ result.assert_main_error(ErrorDomain.STREAM, None)
+
+ assert "Error: '--deps all' is not supported for artifact refs" in result.stderr