Files
photocraft/scripts/test-ci-clear-rolling-cache.py
T

29 lines
1.2 KiB
Python

from importlib.machinery import SourceFileLoader
from pathlib import Path
import unittest
clear = SourceFileLoader('clear', str(Path(__file__).with_name('ci-clear-rolling-cache.py'))).load_module()
class TestClear(unittest.TestCase):
def test_the_build_job_is_saving_once_a_post_step_starts(self):
steps = lambda *s: {'name': 'gate / build (ubuntu-24.04)', 'steps': [{'name': n, 'status': st} for n, st in s]}
self.assertFalse(clear.saving(steps(('Setup', 'completed'), ('Build the test archive', 'in_progress'))))
self.assertTrue(clear.saving(steps(('Build the test archive', 'completed'), ('Post Setup', 'in_progress'))))
def test_only_the_build_job_counts(self):
jobs = [{'name': 'gate / lint (ubuntu-24.04)'}, {'name': 'gate / build (ubuntu-24.04)'}]
self.assertEqual(clear.build_job(jobs), jobs[1])
def test_only_rolling_crates_entries_are_deleted(self):
caches = [
{'key': 'v2-rust-ab-gate-crates-Linux-x64-1-1-Linux-x64-d8-99'},
{'key': 'v2-rust-ab-gate-Windows_NT-x64-ae-88'},
{'key': 'v1-rust-corpus-corpus-Linux-x64-62-99'},
]
self.assertEqual(clear.rolling_entries(caches), caches[:1])
if __name__ == '__main__':
unittest.main()