Skip to content
Snippets Groups Projects
Commit c7bf9e26 authored by vlorentz's avatar vlorentz
Browse files

Run git loader tests on BulkUpdater too.

Summary: Depends on D664.

Reviewers: #reviewers, ardumont

Reviewed By: #reviewers, ardumont

Subscribers: ardumont, swh-public-ci

Maniphest Tasks: T1219

Differential Revision: https://forge.softwareheritage.org/D665
parent 2a3e57db
No related branches found
No related tags found
1 merge request!13Run git loader tests on BulkUpdater too.
......@@ -10,7 +10,7 @@ import subprocess
from swh.loader.git.loader import GitLoader, GitLoaderFromArchive
from swh.loader.core.tests import BaseLoaderTest, LoaderNoStorage
from swh.model.hashutil import hash_to_bytes
from swh.model.hashutil import hash_to_bytes, hash_to_bytehex
class MockStorage0:
......@@ -27,6 +27,9 @@ class MockStorage0:
def revision_missing(self, revisions):
return revisions
def object_find_by_sha1_git(self, ids):
return {}
CONTENT1 = {
'33ab5639bfd8e7b95eb1d8d0b87781d4ffea4d5d', # README v1
......@@ -131,6 +134,42 @@ class MockStorage1:
assert all(isinstance(r, bytes) for r in revisions)
return list(set(revisions) - set(map(hash_to_bytes, REVISIONS1)))
def object_find_by_sha1_git(self, ids):
res = {}
for id_ in ids:
found = []
decoded_id = hash_to_bytehex(id_)
if decoded_id in REVISIONS1:
found.append({
'sha1_git': id_,
'type': 'revision',
'id': id_,
'object_id': 42,
})
elif decoded_id in REVISIONS1.values():
found.append({
'sha1_git': id_,
'type': 'directory',
'id': id_,
'object_id': 42,
})
elif decoded_id == SUBDIR_HASH:
found.append({
'sha1_git': id_,
'type': 'directory',
'id': id_,
'object_id': 42,
})
elif decoded_id in CONTENT1:
found.append({
'sha1_git': id_,
'type': 'content',
'id': id_,
'object_id': 42,
})
res[id_] = found
return res
class LoaderNoStorageMixin(LoaderNoStorage):
def __init__(self):
......@@ -218,7 +257,10 @@ class BaseZipGitLoaderTest(BaseGitLoaderTest):
class GitLoaderTests:
"""Common tests for all git loaders."""
def test_load(self):
"""Loads a simple repository (made available by `setUp()`),
and checks everything was added in the storage."""
res = self.load()
self.assertEqual(res['status'], 'eventful', res)
......@@ -236,6 +278,8 @@ class GitLoaderTests:
self.assertEqual(self.loader.visit_status(), 'full')
def test_load_unchanged(self):
"""Checks loading a repository a second time does not add
any extra data."""
res = self.load()
self.assertEqual(res['status'], 'eventful')
......@@ -246,7 +290,11 @@ class GitLoaderTests:
class DirGitLoaderTest(BaseDirGitLoaderTest, GitLoaderTests):
"""Tests for the GitLoader. Includes the common ones, and
add others that only work with a local dir."""
def _git(self, *cmd):
"""Small wrapper around subprocess to call Git."""
try:
return subprocess.check_output(
['git', '-C', self.destination_path] + list(cmd))
......@@ -256,6 +304,9 @@ class DirGitLoaderTest(BaseDirGitLoaderTest, GitLoaderTests):
raise
def test_load_changed(self):
"""Loads a repository, makes some changes by adding files, commits,
and merges, load it again, and check the storage contains everything
it should."""
# Initial load
res = self.load()
self.assertEqual(res['status'], 'eventful', res)
......@@ -318,4 +369,6 @@ class DirGitLoaderTest(BaseDirGitLoaderTest, GitLoaderTests):
class ZipGitLoaderTest(BaseZipGitLoaderTest, GitLoaderTests):
"""Tests for GitLoaderFromArchive. Imports the common ones
from GitLoaderTests."""
pass
from swh.loader.git.updater import BulkUpdater
from swh.loader.git.tests.test_loader import (
DirGitLoaderTest, LoaderNoStorageMixin)
class BulkUpdaterNoStorage(LoaderNoStorageMixin, BulkUpdater):
"""Subclass of BulkUpdater that uses a mock storage."""
pass
class BulkUpdaterTest(DirGitLoaderTest):
"""Same tests as for the GitLoader, but running on BulkUpdater."""
def setUp(self):
super().setUp()
self.loader = BulkUpdaterNoStorage()
def load(self):
return self.loader.load(
origin_url=self.repo_url)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment