async def test_clear_snapshots(coresys: CoreSys, tmp_path): """Test snapshot cleanup.""" for slug in ["sn1", "sn2", "sn3", "sn4", "sn5"]: temp_tar = Path(tmp_path, f"{slug}.tar") with SecureTarFile(temp_tar, "w"): pass snapshot = Snapshot(coresys, temp_tar) snapshot._data = { # pylint: disable=protected-access ATTR_SLUG: slug, ATTR_DATE: utcnow().isoformat(), ATTR_TYPE: SNAPSHOT_PARTIAL if "1" in slug or "5" in slug else SNAPSHOT_FULL, } coresys.snapshots.snapshots_obj[snapshot.slug] = snapshot newest_full_snapshot = coresys.snapshots.snapshots_obj["sn4"] assert newest_full_snapshot in coresys.snapshots.list_snapshots assert (len([ x for x in coresys.snapshots.list_snapshots if x.sys_type == SNAPSHOT_FULL ]) == 3) coresys.resolution.storage.clean_full_snapshots() assert newest_full_snapshot in coresys.snapshots.list_snapshots assert (len([ x for x in coresys.snapshots.list_snapshots if x.sys_type == SNAPSHOT_FULL ]) == 1)
async def test_fixup(coresys: CoreSys, tmp_path): """Test fixup.""" clear_full_backup = FixupClearFullBackup(coresys) assert not clear_full_backup.auto coresys.resolution.suggestions = Suggestion( SuggestionType.CLEAR_FULL_BACKUP, ContextType.SYSTEM) for slug in ["sn1", "sn2", "sn3", "sn4", "sn5"]: temp_tar = Path(tmp_path, f"{slug}.tar") with SecureTarFile(temp_tar, "w"): pass backup = Backup(coresys, temp_tar) backup._data = { # pylint: disable=protected-access ATTR_SLUG: slug, ATTR_DATE: utcnow().isoformat(), ATTR_TYPE: BackupType.PARTIAL if "1" in slug or "5" in slug else BackupType.FULL, } coresys.backups._backups[backup.slug] = backup newest_full_backup = coresys.backups._backups["sn4"] assert newest_full_backup in coresys.backups.list_backups assert (len([ x for x in coresys.backups.list_backups if x.sys_type == BackupType.FULL ]) == 3) await clear_full_backup() assert newest_full_backup in coresys.backups.list_backups assert (len([ x for x in coresys.backups.list_backups if x.sys_type == BackupType.FULL ]) == 1) assert len(coresys.resolution.suggestions) == 0
async def test_fixup(coresys: CoreSys, tmp_path): """Test fixup.""" clear_full_snapshot = FixupClearFullSnapshot(coresys) assert not clear_full_snapshot.auto coresys.resolution.suggestions = Suggestion( SuggestionType.CLEAR_FULL_SNAPSHOT, ContextType.SYSTEM) for slug in ["sn1", "sn2", "sn3", "sn4", "sn5"]: temp_tar = Path(tmp_path, f"{slug}.tar") with SecureTarFile(temp_tar, "w"): pass snapshot = Snapshot(coresys, temp_tar) snapshot._data = { # pylint: disable=protected-access ATTR_SLUG: slug, ATTR_DATE: utcnow().isoformat(), ATTR_TYPE: SNAPSHOT_PARTIAL if "1" in slug or "5" in slug else SNAPSHOT_FULL, } coresys.snapshots.snapshots_obj[snapshot.slug] = snapshot newest_full_snapshot = coresys.snapshots.snapshots_obj["sn4"] assert newest_full_snapshot in coresys.snapshots.list_snapshots assert (len([ x for x in coresys.snapshots.list_snapshots if x.sys_type == SNAPSHOT_FULL ]) == 3) await clear_full_snapshot() assert newest_full_snapshot in coresys.snapshots.list_snapshots assert (len([ x for x in coresys.snapshots.list_snapshots if x.sys_type == SNAPSHOT_FULL ]) == 1) assert len(coresys.resolution.suggestions) == 0
async def test_fixup_error(coresys: CoreSys): """Test fixup.""" system_execute_integrity = FixupSystemExecuteIntegrity(coresys) assert system_execute_integrity.auto coresys.resolution.suggestions = Suggestion( SuggestionType.EXECUTE_INTEGRITY, ContextType.SYSTEM) coresys.resolution.issues = Issue(IssueType.TRUST, ContextType.SYSTEM) coresys.security.integrity_check = AsyncMock(return_value=IntegrityResult( ContentTrustResult.FAILED, ContentTrustResult.PASS, {"audio": ContentTrustResult.PASS}, )) with time_machine.travel(utcnow() + timedelta(hours=24)): await system_execute_integrity() assert coresys.security.integrity_check.called assert len(coresys.resolution.suggestions) == 1 assert len(coresys.resolution.issues) == 1