Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/tests/test_revision.py
from os import listdir | import json | ||||
from pathlib import Path | from os import listdir, readlink | ||||
from swh.fuse.tests.test_directory import get_rootdir_entries | from swh.fuse.tests.common import get_data_from_archive | ||||
from swh.fuse.tests.data.config import ROOT_DIR, ROOT_REV | |||||
from .api_data import ROOTREV_SWHID | |||||
def test_access_meta(fuse_mntdir): | |||||
file_path = fuse_mntdir / "archive" / ROOT_REV / "meta.json" | |||||
expected = json.dumps(get_data_from_archive(ROOT_REV)) | |||||
assert file_path.read_text() == expected | |||||
def test_symlinks_exist(fuse_mntdir): | |||||
rootrev_dir = Path(fuse_mntdir, "archive", ROOTREV_SWHID) | |||||
assert Path(rootrev_dir, "root").is_symlink() | |||||
assert Path(rootrev_dir, "parent").is_symlink() | |||||
assert Path(rootrev_dir, "parents").is_dir() | |||||
assert Path(rootrev_dir, "meta.json").is_symlink() | |||||
def test_list_root(fuse_mntdir): | |||||
dir_path = fuse_mntdir / "archive" / ROOT_REV / "root" | |||||
dir_meta = get_data_from_archive(ROOT_DIR) | |||||
expected = [x["name"] for x in dir_meta] | |||||
actual = listdir(dir_path) | |||||
assert set(actual) == set(expected) | |||||
def test_ls_rootdir(fuse_mntdir): | |||||
expected = get_rootdir_entries() | |||||
rootdir_path = Path(fuse_mntdir, "archive", ROOTREV_SWHID, "root") | def test_list_parents(fuse_mntdir): | ||||
actual = listdir(rootdir_path) | rev_meta = get_data_from_archive(ROOT_REV) | ||||
assert actual == expected | dir_path = fuse_mntdir / "archive" / ROOT_REV / "parents" | ||||
for i, parent in enumerate(rev_meta["parents"]): | |||||
parent_path = dir_path / str(i + 1) | |||||
parent_swhid = f"swh:1:rev:{parent['id']}" | |||||
assert parent_path.is_symlink() | |||||
assert readlink(parent_path) == f"../../../archive/{parent_swhid}" | |||||
def test_list_parent(fuse_mntdir): | |||||
file_path = fuse_mntdir / "archive" / ROOT_REV / "parent" | |||||
assert file_path.is_symlink() | |||||
assert readlink(file_path) == "parents/1/" |