def test_farmfs_blob_broken(tmp_path, capsys): root = Path(str(tmp_path)) r1 = farmfs_ui(['mkfs'], root) captured = capsys.readouterr() assert r1 == 0 a = Path('a', root) with a.open('w') as a_fd: a_fd.write('a') a_csum = str(a.checksum()) r2 = farmfs_ui(['freeze'], root) captured = capsys.readouterr() assert r2 == 0 a_blob = a.readlink() a_blob.unlink() r3 = farmfs_ui(['fsck', '--broken'], root) captured = capsys.readouterr() assert captured.out == a_csum + "\n\t<tree>\ta\n" assert captured.err == '' assert r3 == 1 # Test relative pathing. d = Path('d', root) d.mkdir() r4 = farmfs_ui(['fsck', '--broken'], d) captured = capsys.readouterr() assert captured.out == a_csum + "\n\t<tree>\t../a\n" assert captured.err == '' assert r3 == 1
def test_farmfs_status(tmp_path, capsys): tmp = Path(str(tmp_path)) r1 = farmfs_ui(['mkfs'], tmp) captured = capsys.readouterr() assert r1 == 0 a = Path('a', tmp) with a.open('w') as a_fd: a_fd.write('a') r2 = farmfs_ui(['status'], tmp) captured = capsys.readouterr() assert captured.out == "a\n" assert captured.err == "" assert r2 == 0 # Test relative status report. d = Path('d', tmp) d.mkdir() r3 = farmfs_ui(['status'], d) captured = capsys.readouterr() assert captured.out == "../a\n" assert captured.err == "" assert r3 == 0 # Freeze a r4 = farmfs_ui(['freeze'], tmp) captured = capsys.readouterr() assert r4 == 0 # assert captured.out == "" assert captured.err == "" r5 = farmfs_ui(['status'], tmp) captured = capsys.readouterr() assert captured.out == "" assert captured.err == "" assert r5 == 0
def test_farmfs_status(vol, capsys): a = Path('a', vol) with a.open('w') as a_fd: a_fd.write('a') r = farmfs_ui(['status'], vol) captured = capsys.readouterr() assert captured.out == "a\n" assert captured.err == "" assert r == 0 # Test relative status report. d = Path('d', vol) d.mkdir() r = farmfs_ui(['status'], d) captured = capsys.readouterr() assert captured.out == "../a\n" assert captured.err == "" assert r == 0 # Freeze a r = farmfs_ui(['freeze'], vol) captured = capsys.readouterr() assert r == 0 # assert captured.out == "" assert captured.err == "" r = farmfs_ui(['status'], vol) captured = capsys.readouterr() assert captured.out == "" assert captured.err == "" assert r == 0
class KeyDBWrapper: def __init__(self, root): self.root = Path(root) def __enter__(self): ensure_absent(self.root) self.root.mkdir() return KeyDB(self.root) def __exit__(self, type, value, traceback): ensure_absent(self.root)
class KeyDBWrapper: def __init__(self, datadir): self.root = Path(datadir) def __enter__(self): ensure_absent(self.root) self.root.mkdir() return KeyDB(self.root) def __exit__(self, type, value, traceback): ensure_absent(self.root)
def test_create_dir(tmp_path): a = Path(str(tmp_path)).join('a') b = a.join('b') assert a.isdir() == False assert b.isdir() == False # Cannot create with missing parents. with pytest.raises(OSError) as e_info: b.mkdir() assert e_info.value.errno == FileDoesNotExist assert a.isdir() == False assert b.isdir() == False # Create a a.mkdir() assert a.isdir() == True assert b.isdir() == False # idempotent a.mkdir() assert a.isdir() == True assert b.isdir() == False
def test_farmfs_similarity(vol, capsys): a_path = Path("a", vol) a_path.mkdir() b_path = Path("b", vol) b_path.mkdir() for i in [1, 2, 3]: with Path(str(i), a_path).open('w') as fd: fd.write(str(i)) for i in [1, 2, 4, 5]: with Path(str(i), b_path).open('w') as fd: fd.write(str(i)) # Freeze r = farmfs_ui(['freeze'], vol) captured = capsys.readouterr() assert r == 0 r = farmfs_ui(['similarity', "a", "b"], vol) captured = capsys.readouterr() assert r == 0 assert captured.out == "left\tboth\tright\tjaccard_similarity\n1\t2\t2\t0.4\n"
def test_farmfs_freeze_snap_thaw(tmp_path, parent, child, snap, content, read, write): root = Path(str(tmp_path)) r1 = farmfs_ui(['mkfs'], root) assert r1 == 0 parent_path = Path(parent, root) child_path = Path(child, parent_path) parent_path.mkdir() with child_path.open(write) as child_fd: child_fd.write(content) assert parent_path.isdir() assert child_path.isfile() r2 = farmfs_ui(['freeze'], root) assert r2 == 0 assert parent_path.isdir() assert child_path.islink() blob = child_path.readlink() assert blob.isfile() userdata = Path('.farmfs/userdata', root) assert userdata in list(blob.parents()) with blob.open(read) as check_fd: check_content = check_fd.read() assert check_content == content r3 = farmfs_ui(['snap', 'make', snap], root) assert r3 == 0 snap_path = root.join(".farmfs/snap").join(snap) snap_path.exists() child_path.unlink() assert not child_path.exists() assert blob.isfile() r4 = farmfs_ui(['snap', 'restore', snap], root) assert r4 == 0 assert child_path.islink() assert blob.isfile() assert child_path.readlink() == blob r5 = farmfs_ui(['thaw', parent], root) assert r5 == 0 assert child_path.isfile() r6 = farmfs_ui(['freeze', child], parent_path) assert r6 == 0 child_path.islink()
def test_farmfs_freeze_snap_thaw(vol, parent, child, snap, content, read, write): parent_path = Path(parent, vol) child_path = Path(child, parent_path) parent_path.mkdir() with child_path.open(write) as child_fd: child_fd.write(content) assert parent_path.isdir() assert child_path.isfile() r = farmfs_ui(['freeze'], vol) assert r == 0 assert parent_path.isdir() assert child_path.islink() blob = child_path.readlink() assert blob.isfile() userdata = Path('.farmfs/userdata', vol) assert userdata in list(blob.parents()) with blob.open(read) as check_fd: check_content = check_fd.read() assert check_content == content r = farmfs_ui(['snap', 'make', snap], vol) assert r == 0 snap_path = vol.join(".farmfs/snap").join(snap) snap_path.exists() child_path.unlink() assert not child_path.exists() assert blob.isfile() r = farmfs_ui(['snap', 'restore', snap], vol) assert r == 0 assert child_path.islink() assert blob.isfile() assert child_path.readlink() == blob r = farmfs_ui(['thaw', parent], vol) assert r == 0 assert child_path.isfile() r = farmfs_ui(['freeze', child], parent_path) assert r == 0 child_path.islink()
def test_farmfs_blob_broken(vol, capsys): a = Path('a', vol) with a.open('w') as a_fd: a_fd.write('a') a_csum = str(a.checksum()) r = farmfs_ui(['freeze'], vol) captured = capsys.readouterr() assert r == 0 a_blob = a.readlink() a_blob.unlink() r = farmfs_ui(['fsck', '--broken'], vol) captured = capsys.readouterr() assert captured.out == a_csum + "\n\t<tree>\ta\n" assert captured.err == '' assert r == 1 # Test relative pathing. d = Path('d', vol) d.mkdir() r = farmfs_ui(['fsck', '--broken'], d) captured = capsys.readouterr() assert captured.out == a_csum + "\n\t<tree>\t../a\n" assert captured.err == '' assert r == 1
def test_fix_link(tmp_path, capsys): test_dir = Path(str(tmp_path)) # Make roots vol1 = Path("vol1", test_dir) vol1.mkdir() vol2 = Path("vol2", test_dir) vol2.mkdir() # Setup vol1 r = farmfs_ui(['mkfs'], vol1) captured = capsys.readouterr() assert r == 0 a = Path('a', vol1) b = Path('b', vol1) c = Path('c', vol1) cd = Path('c/d', vol1) # Make a,b; freeze, snap, delete with a.open('w') as fd: fd.write('a') a_csum = str(a.checksum()) with b.open('w') as fd: fd.write('b') r = farmfs_ui(['freeze'], vol1) captured = capsys.readouterr() assert r == 0 # Setup vol2 r = farmfs_ui(['mkfs'], vol2) captured = capsys.readouterr() assert r == 0 e = Path('e', vol2) with e.open('w') as fd: fd.write('e') e_csum = str(e.checksum()) r = farmfs_ui(['freeze'], vol2) captured = capsys.readouterr() assert r == 0 # Setup remote r = farmfs_ui(['remote', 'add', 'vol2', '../vol2'], vol1) captured = capsys.readouterr() assert r == 0 # Check file type for a r = dbg_ui(['fix', 'link', a_csum, 'b'], vol1) captured = capsys.readouterr() assert r == 0 assert captured.err == "" assert captured.out == "" assert a.readlink() == b.readlink() # Try to fix link to a missing blob, e with pytest.raises(ValueError): r = dbg_ui(['fix', 'link', e_csum, 'e'], vol1) captured = capsys.readouterr() assert r == 0 assert captured.err == "" assert captured.out == "blob " + e_csum + " doesn't exist\n" # Pull e from remote. r = dbg_ui(['fix', 'link', '--remote', 'vol2', e_csum, 'e'], vol1) captured = capsys.readouterr() assert r == 0 assert captured.out == "blob " + e_csum + " doesn't exist\n" assert captured.err == "" # Try to fix a link to a missing target. r = dbg_ui(['fix', 'link', a_csum, 'c'], vol1) captured = capsys.readouterr() assert r == 0 assert captured.err == "" assert captured.out == "" assert a.readlink() == c.readlink() # Try to fix a link to a missing target, in a dir which is blobked by a link r = dbg_ui(['fix', 'link', a_csum, 'c/d'], vol1) captured = capsys.readouterr() assert r == 0 assert captured.err == "" assert captured.out == "" assert a.readlink() == cd.readlink()