Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_loader.py
Show All 20 Lines | |||||
) | ) | ||||
from swh.loader.svn.utils import init_svn_repo_from_dump | from swh.loader.svn.utils import init_svn_repo_from_dump | ||||
from swh.loader.tests import ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
check_snapshot, | check_snapshot, | ||||
get_stats, | get_stats, | ||||
prepare_repository_from_archive, | prepare_repository_from_archive, | ||||
) | ) | ||||
from swh.model.from_disk import DentryPerms | |||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Snapshot, SnapshotBranch, TargetType | from swh.model.model import Snapshot, SnapshotBranch, TargetType | ||||
GOURMET_SNAPSHOT = Snapshot( | GOURMET_SNAPSHOT = Snapshot( | ||||
id=hash_to_bytes("889cacc2731e3312abfb2b1a0c18ade82a949e07"), | id=hash_to_bytes("889cacc2731e3312abfb2b1a0c18ade82a949e07"), | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch( | b"HEAD": SnapshotBranch( | ||||
target=hash_to_bytes("4876cb10aec6f708f7466dddf547567b65f6c39c"), | target=hash_to_bytes("4876cb10aec6f708f7466dddf547567b65f6c39c"), | ||||
▲ Show 20 Lines • Show All 865 Lines • ▼ Show 20 Lines | assert get_stats(loader.storage) == { | ||||
"directory": 5, | "directory": 5, | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 0, | ||||
"revision": 3, | "revision": 3, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} | } | ||||
def test_loader_eol_style_on_svn_link_handling(swh_storage, tmp_path): | |||||
# create a repository | |||||
repo_path = os.path.join(tmp_path, "tmprepo") | |||||
repos.create(repo_path) | |||||
repo_url = f"file://{repo_path}" | |||||
# first commit | |||||
add_commit( | |||||
repo_url, | |||||
( | |||||
"Add a regular file, a directory and a link to the regular file " | |||||
"in the directory. Set svn:eol-style property for the regular " | |||||
"file and the link. Set svn:special property for the link." | |||||
), | |||||
[ | |||||
CommitChange( | |||||
change_type=CommitChangeType.AddOrUpdate, | |||||
path="file_with_crlf_eol.txt", | |||||
properties={"svn:eol-style": "native"}, | |||||
data=b"Hello world!\r\n", | |||||
), | |||||
CommitChange( | |||||
change_type=CommitChangeType.AddOrUpdate, | |||||
path="directory/file_with_crlf_eol.txt", | |||||
properties={"svn:eol-style": "native", "svn:special": "*"}, | |||||
data=b"link ../file_with_crlf_eol.txt", | |||||
), | |||||
], | |||||
) | |||||
# instantiate a svn loader checking after each processed revision that | |||||
# the repository filesystem it reconstructed does not differ from a subversion | |||||
# export of that revision | |||||
loader = SvnLoader( | |||||
swh_storage, repo_url, destination_path=tmp_path, check_revision=1 | |||||
) | |||||
assert loader.load() == {"status": "eventful"} | |||||
assert loader.visit_status() == "full" | |||||
# check loaded objects are those expected | |||||
assert get_stats(loader.storage) == { | |||||
"content": 2, | |||||
"directory": 2, | |||||
"origin": 1, | |||||
"origin_visit": 1, | |||||
"release": 0, | |||||
"revision": 1, | |||||
"skipped_content": 0, | |||||
"snapshot": 1, | |||||
} | |||||
root_dir = loader.snapshot.branches[b"HEAD"].target | |||||
revision = loader.storage.revision_get([root_dir])[0] | |||||
paths = {} | |||||
for entry in loader.storage.directory_ls(revision.directory, recursive=True): | |||||
paths[entry["name"]] = entry | |||||
assert ( | |||||
loader.storage.content_get_data(paths[b"file_with_crlf_eol.txt"]["sha1"]) | |||||
== b"Hello world!\n" | |||||
) | |||||
assert paths[b"directory/file_with_crlf_eol.txt"]["perms"] == DentryPerms.symlink | |||||
assert ( | |||||
loader.storage.content_get_data( | |||||
paths[b"directory/file_with_crlf_eol.txt"]["sha1"] | |||||
) | |||||
== b"../file_with_crlf_eol.txt" | |||||
) |