| 1 | import runpy |
| 2 | import unittest |
| 3 | from pathlib import Path |
| 4 | |
| 5 | |
| 6 | sync = runpy.run_path(str(Path(__file__).with_name("sync-marketplace.py"))) |
| 7 | archives = sync["admitted_dsh_archives"]() |
| 8 | check_remote = sync["check_remote"] |
| 9 | |
| 10 | |
| 11 | def candidate(key): |
| 12 | source, version, digest = key |
| 13 | return {"name": "fixture", "source": source, "version": version, "sha256": digest} |
| 14 | |
| 15 | |
| 16 | class SnapshotPins(unittest.TestCase): |
| 17 | def test_admitted_archive_without_a_declared_os_filter(self): |
| 18 | entry = candidate(next(key for key in archives if "dsh-code-review/" in key[0])) |
| 19 | check_remote(entry, archives) |
| 20 | self.assertNotIn("platforms", entry) |
| 21 | |
| 22 | def test_os_declaration_round_trips(self): |
| 23 | entry = candidate(next(key for key in archives if "/dsh-cost-meter/" in key[0])) |
| 24 | check_remote(entry, archives) |
| 25 | self.assertEqual(entry["platforms"], ["macos", "linux", "windows"]) |
| 26 | |
| 27 | def test_omission_is_bound_to_the_entire_reviewed_pin(self): |
| 28 | key = next(key for key in archives if "dsh-code-review/" in key[0]) |
| 29 | original = candidate(key) |
| 30 | for changes in ( |
| 31 | {"source": original["source"] + "?mirror=1"}, |
| 32 | {"version": "2.0.0"}, |
| 33 | {"sha256": "0" * 64}, |
| 34 | {"source": "https://example.org/plugin.tgz"}, |
| 35 | ): |
| 36 | with self.subTest(changes=changes), self.assertRaises(SystemExit): |
| 37 | check_remote({**original, **changes}, archives) |
| 38 | for declarations in ({"os": ["darwin"]}, {"dsh.bundle.platforms": ["wsl"]}): |
| 39 | with self.subTest(declarations=declarations), self.assertRaises(SystemExit): |
| 40 | check_remote(original.copy(), {key: declarations}) |
| 41 | |
| 42 | def test_generic_remote_requires_a_version_digest_and_explicit_valid_platforms(self): |
| 43 | valid = {"name": "binary", "source": "https://example.org/v1/plugin.tgz", |
| 44 | "version": "1.0.0", "sha256": "a" * 64, "platforms": ["macos"]} |
| 45 | check_remote(valid, archives) |
| 46 | for changes in ({"source": "https://example.org/latest/plugin.tgz"}, {"version": ""}, |
| 47 | {"sha256": "short"}, {"platforms": None}, {"platforms": []}, |
| 48 | {"platforms": ["macos", "macos"]}, {"platforms": ["unknown"]}): |
| 49 | with self.subTest(changes=changes), self.assertRaises(SystemExit): |
| 50 | check_remote({**valid, **changes}, archives) |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | unittest.main() |
| 55 |