Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_git_bare_cooker.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
""" | """ | ||||
This module contains additional tests for the bare cooker. | This module contains additional tests for the bare cooker. | ||||
Generic cooker tests (eg. without swh-graph) in test_cookers.py also | Generic cooker tests (eg. without swh-graph) in test_cookers.py also | ||||
run on the bare cooker. | run on the bare cooker. | ||||
""" | """ | ||||
import datetime | import datetime | ||||
import glob | |||||
import io | import io | ||||
import subprocess | import subprocess | ||||
import tarfile | import tarfile | ||||
import tempfile | import tempfile | ||||
import unittest.mock | import unittest.mock | ||||
import pytest | import pytest | ||||
from pytest import param | from pytest import param | ||||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | def test_graph_revisions(swh_storage, up_to_date_graph, snapshot, tag, weird_branches): | ||||
swh_storage = unittest.mock.MagicMock(wraps=swh_storage) | swh_storage = unittest.mock.MagicMock(wraps=swh_storage) | ||||
# Add all objects to graph | # Add all objects to graph | ||||
swh_graph = unittest.mock.Mock(wraps=GraphClient(nodes=nodes, edges=edges)) | swh_graph = unittest.mock.Mock(wraps=GraphClient(nodes=nodes, edges=edges)) | ||||
# Cook | # Cook | ||||
backend = InMemoryVaultBackend() | backend = InMemoryVaultBackend() | ||||
if snapshot: | if snapshot: | ||||
cooker_name = "snapshot_gitbare" | cooked_swhid = snp.swhid() | ||||
cooked_id = snp.id | |||||
else: | else: | ||||
cooker_name = "revision_gitbare" | cooked_swhid = rev2.swhid() | ||||
cooked_id = rev2.id | |||||
cooker = GitBareCooker( | cooker = GitBareCooker( | ||||
cooker_name, cooked_id, backend=backend, storage=swh_storage, graph=swh_graph, | cooked_swhid, backend=backend, storage=swh_storage, graph=swh_graph, | ||||
) | ) | ||||
if weird_branches: | if weird_branches: | ||||
# git-fsck now rejects refs pointing to trees and blobs, | # git-fsck now rejects refs pointing to trees and blobs, | ||||
# but some old git repos have them. | # but some old git repos have them. | ||||
cooker.use_fsck = False | cooker.use_fsck = False | ||||
cooker.cook() | cooker.cook() | ||||
# Get bundle | # Get bundle | ||||
bundle = backend.fetch(cooker_name, cooked_id) | bundle = backend.fetch("git_bare", cooked_swhid) | ||||
# Extract bundle and make sure both revisions are in it | # Extract bundle and make sure both revisions are in it | ||||
with tempfile.TemporaryDirectory("swh-vault-test-bare") as tempdir: | with tempfile.TemporaryDirectory("swh-vault-test-bare") as tempdir: | ||||
with tarfile.open(fileobj=io.BytesIO(bundle)) as tf: | with tarfile.open(fileobj=io.BytesIO(bundle)) as tf: | ||||
tf.extractall(tempdir) | tf.extractall(tempdir) | ||||
output = subprocess.check_output( | output = subprocess.check_output( | ||||
[ | [ | ||||
"git", | "git", | ||||
"-C", | "-C", | ||||
glob.glob(f"{tempdir}/*{cooked_id.hex()}.git")[0], | f"{tempdir}/{cooked_swhid}.git", | ||||
"log", | "log", | ||||
"--format=oneline", | "--format=oneline", | ||||
"--decorate=", | "--decorate=", | ||||
] | ] | ||||
) | ) | ||||
assert output.decode() == f"{rev2.id.hex()} msg2\n{rev1.id.hex()} msg1\n" | assert output.decode() == f"{rev2.id.hex()} msg2\n{rev1.id.hex()} msg1\n" | ||||
Show All 27 Lines |