def test_missing(vol, capsys): a = Path('a', vol) b = Path('b', vol) b2 = Path('b2', vol) c = Path('c.txt', vol) d = Path('d', vol) ignore = Path('.farmignore', vol) # Make a,b,b2; freeze, snap, delete with a.open('w') as fd: fd.write( 'a_masked' ) # Checksum for a_mask should not appear missing, as a exists. with b.open('w') as fd: fd.write('b') b_csum = str(b.checksum()) with b2.open('w') as fd: fd.write('b') with c.open('w') as fd: fd.write('c') r = farmfs_ui(['freeze'], vol) captured = capsys.readouterr() assert r == 0 r = farmfs_ui(['snap', 'make', 'snk1'], vol) captured = capsys.readouterr() # Remove b's a.unlink() with a.open('w') as fd: fd.write('a') b.unlink() b2.unlink() c.unlink() #Setup ignore with ignore.open('w') as fd: fd.write('*.txt\n*/*.txt\n') # Look for missing checksum: r = dbg_ui(['missing', 'snk1'], vol) captured = capsys.readouterr() assert r == 0 assert captured.err == "" assert captured.out == b_csum + "\tb\n" + b_csum + "\tb2\n" # Make d; freeze snap, delete with d.open('w') as fd: fd.write('d') d_csum = str(d.checksum()) r = farmfs_ui(['freeze'], vol) captured = capsys.readouterr() assert r == 0 r = farmfs_ui(['snap', 'make', 'snk2'], vol) captured = capsys.readouterr() d.unlink() # Look for missing checksum: r = dbg_ui(['missing', 'snk1', 'snk2'], vol) captured = capsys.readouterr() assert r == 0 assert captured.err == "" removed_lines = set(['', b_csum + "\tb", b_csum + "\tb2", d_csum + "\td"]) assert set(captured.out.split("\n")) == removed_lines
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_gc(tmp_path, capsys): root = Path(str(tmp_path)) sk = Path('sk', root) sd = Path('sd', root) tk = Path('tk', root) td = Path('td', root) # Make the Farm r = farmfs_ui(['mkfs'], root) captured = capsys.readouterr() assert r == 0 # Make sk, freeze, snap, delete with sk.open('w') as fd: fd.write('sk') r = farmfs_ui(['freeze'], root) captured = capsys.readouterr() assert r == 0 sk_blob = sk.readlink() r = farmfs_ui(['snap', 'make', 'snk'], root) captured = capsys.readouterr() assert r == 0 sk.unlink() # Make sd, freeze, snap, delete, delete snap with sd.open('w') as fd: fd.write('sd') sd_csum = str(sd.checksum()) r = farmfs_ui(['freeze'], root) captured = capsys.readouterr() assert r == 0 sd_blob = sd.readlink() r = farmfs_ui(['snap', 'make', 'snd'], root) captured = capsys.readouterr() assert r == 0 sd.unlink() r = farmfs_ui(['snap', 'delete', 'snd'], root) captured = capsys.readouterr() assert r == 0 # Make tk and td, freeze, delete td with tk.open('w') as fd: fd.write('tk') with td.open('w') as fd: fd.write('td') r = farmfs_ui(['freeze'], root) captured = capsys.readouterr() assert r == 0 tk_blob = tk.readlink() td_blob = td.readlink() td_csum = str(td.checksum()) td.unlink() # GC --noop assert sk_blob.exists() assert sd_blob.exists() assert tk_blob.exists() assert td_blob.exists() r = farmfs_ui(['gc', '--noop'], root) captured = capsys.readouterr() assert captured.out == 'Removing ' + sd_csum + '\nRemoving ' + td_csum + '\n' assert captured.err == '' assert r == 0 assert sk_blob.exists() assert sd_blob.exists() assert tk_blob.exists() assert td_blob.exists() # GC r = farmfs_ui(['gc'], root) captured = capsys.readouterr() assert captured.out == 'Removing ' + sd_csum + '\nRemoving ' + td_csum + '\n' assert captured.err == '' assert r == 0 assert sk_blob.exists() assert not sd_blob.exists() assert tk_blob.exists() assert not td_blob.exists()