in src/buildstream/_testing/_sourcetests/mirror.py [0:0]
def test_mirror_track_upstream_absent(cli, tmpdir, datafiles, kind):
project_dir = str(datafiles)
bin_files_path = os.path.join(project_dir, "files", "bin-files", "usr")
dev_files_path = os.path.join(project_dir, "files", "dev-files", "usr")
upstream_repodir = os.path.join(str(tmpdir), "upstream")
mirror_repodir = os.path.join(str(tmpdir), "mirror")
element_dir = os.path.join(project_dir, "elements")
# Create repo objects of the upstream and mirror
upstream_repo = create_repo(kind, upstream_repodir)
upstream_ref = upstream_repo.create(bin_files_path)
mirror_repo = upstream_repo.copy(mirror_repodir)
mirror_ref = upstream_ref
upstream_ref = upstream_repo.create(dev_files_path)
# Configure to allow tracking mirrors as well as upstream
cli.configure({"track": {"source": "all"}})
element = {"kind": "import", "sources": [upstream_repo.source_config(ref=upstream_ref)]}
element_name = "test.bst"
element_path = os.path.join(element_dir, element_name)
full_repo = element["sources"][0]["url"]
_, repo_name = os.path.split(full_repo)
alias = "foo-" + kind
aliased_repo = alias + ":" + repo_name
element["sources"][0]["url"] = aliased_repo
full_mirror = mirror_repo.source_config()["url"]
mirror_map, _ = os.path.split(full_mirror)
_yaml.roundtrip_dump(element, element_path)
_set_project_mirrors_and_aliases(
project_dir,
[
{
"name": "middle-earth",
"aliases": {
alias: [mirror_map + "/"],
},
},
],
{alias: "http://www.example.com"},
)
result = cli.run(project=project_dir, args=["source", "track", element_name])
result.assert_success()
# Check that tracking fell back to the mirror
new_element = _yaml.load(element_path, shortname=element_name)
source = new_element.get_sequence("sources").mapping_at(0)
if "ref" in source:
assert source.get_str("ref") == mirror_ref