summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-07-01 17:31:48 +0200
committerJürg Billeter <j@bitron.ch>2020-07-06 09:43:22 +0200
commit4a2365378e06a5800f62a30a61f8b05a58202e45 (patch)
tree0ef6fabeb285363ed1ef1ac07d9e57f95a4c7465
parent03555170771862f5bae459c7a0c035c7769fb025 (diff)
downloadbuildstream-4a2365378e06a5800f62a30a61f8b05a58202e45.tar.gz
tests/sourcecache/fetch.py: Use `bst source push` to replace hack
-rw-r--r--tests/sourcecache/fetch.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/tests/sourcecache/fetch.py b/tests/sourcecache/fetch.py
index 889de62f0..1e54a98a5 100644
--- a/tests/sourcecache/fetch.py
+++ b/tests/sourcecache/fetch.py
@@ -35,15 +35,6 @@ from tests.testutils import create_artifact_share, dummy_context
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project")
-def move_local_cas_to_remote_source_share(local, remote):
- shutil.rmtree(os.path.join(remote, "repo", "cas"))
- shutil.rmtree(os.path.join(remote, "repo", "source_protos"))
- shutil.move(os.path.join(local, "source_protos"), os.path.join(remote, "repo"))
- shutil.move(os.path.join(local, "cas"), os.path.join(remote, "repo"))
- shutil.rmtree(os.path.join(local, "sources"))
- shutil.rmtree(os.path.join(local, "artifacts"))
-
-
def create_test_element(tmpdir, project_dir):
repo = create_repo("git", str(tmpdir))
ref = repo.create(os.path.join(project_dir, "files"))
@@ -98,11 +89,17 @@ def test_source_fetch(cli, tmpdir, datafiles):
sourcecache = context.sourcecache
digest = sourcecache.export(source)._get_digest()
- move_local_cas_to_remote_source_share(str(cache_dir), share.directory)
+ # Push the source to the remote
+ res = cli.run(project=project_dir, args=["source", "push", "--remote", share.repo, element_name])
+ res.assert_success()
- # check the share has the object
+ # check the share has the proto and the object
+ assert share.get_source_proto(source._get_source_name())
assert share.has_object(digest)
+ # Delete the source locally
+ shutil.rmtree(os.path.join(str(cache_dir), "sources"))
+ shutil.rmtree(os.path.join(str(cache_dir), "cas"))
state = cli.get_element_state(project_dir, element_name)
assert state == "fetch needed"
@@ -111,6 +108,12 @@ def test_source_fetch(cli, tmpdir, datafiles):
res.assert_success()
assert "Pulled source" in res.stderr
+ with context_with_source_cache(cli, cache_dir, share, tmpdir) as context:
+ project = Project(project_dir, context)
+ project.ensure_fully_loaded()
+
+ element = project.load_elements([element_name])[0]
+
# check that we have the source in the cas now and it's not fetched
assert element._has_all_sources_in_source_cache()
assert os.listdir(os.path.join(str(tmpdir), "cache", "sources", "git")) == []
@@ -206,13 +209,18 @@ def test_source_pull_partial_fallback_fetch(cli, tmpdir, datafiles):
sourcecache = context.sourcecache
digest = sourcecache.export(source)._get_digest()
- move_local_cas_to_remote_source_share(str(cache_dir), share.directory)
+ # Push the source to the remote
+ res = cli.run(project=project_dir, args=["source", "push", "--remote", share.repo, element_name])
+ res.assert_success()
# Remove the cas content, only keep the proto and such around
shutil.rmtree(os.path.join(str(tmpdir), "sourceshare", "repo", "cas", "objects"))
# check the share doesn't have the object
assert not share.has_object(digest)
+ # Delete the source locally
+ shutil.rmtree(os.path.join(str(cache_dir), "sources"))
+ shutil.rmtree(os.path.join(str(cache_dir), "cas"))
state = cli.get_element_state(project_dir, element_name)
assert state == "fetch needed"