forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stable_promotion_verifiers.py
More file actions
69 lines (55 loc) · 2.67 KB
/
Copy pathtest_stable_promotion_verifiers.py
File metadata and controls
69 lines (55 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from __future__ import annotations
import importlib.util
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def _load(name: str):
path = ROOT / ".github/scripts" / name
spec = importlib.util.spec_from_file_location(name.replace("-", "_"), path)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
APPCAST = _load("verify_stable_appcast.py")
POINTER = _load("check_stable_pointer_precondition.py")
def _fields(release_id: str, generation: int) -> dict:
return {"release_id": {"stringValue": release_id}, "generation": {"integerValue": str(generation)}}
class StablePromotionVerifierTests(unittest.TestCase):
def test_lost_response_retry_accepts_only_the_expected_next_generation(self):
POINTER.verify(
beta=_fields("target", 4),
stable=_fields("target", 8),
release_id="target",
expected_release_id="previous",
expected_generation=7,
operation="promote",
)
with self.assertRaisesRegex(ValueError, "unrelated generation drift"):
POINTER.verify(
beta=_fields("target", 4),
stable=_fields("target", 9),
release_id="target",
expected_release_id="previous",
expected_generation=7,
operation="promote",
)
def test_stable_appcast_ignores_beta_item_but_rejects_two_default_items(self):
manifest = {
"build_number": 9,
"version": "1.0",
"zip_url": "https://example.test/Omi.zip",
"ed_signature": "sig",
}
xml = '''<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel>
<item><enclosure url="https://example.test/Omi.zip" sparkle:edSignature="sig"/><sparkle:version>9</sparkle:version><sparkle:shortVersionString>1.0</sparkle:shortVersionString></item>
<item><enclosure url="https://example.test/Omi.zip" sparkle:edSignature="sig"/><sparkle:version>9</sparkle:version><sparkle:shortVersionString>1.0</sparkle:shortVersionString><sparkle:channel>beta</sparkle:channel></item></channel></rss>'''
with tempfile.TemporaryDirectory() as directory:
feed = Path(directory) / "feed.xml"
feed.write_text(xml, encoding="utf-8")
APPCAST.verify(manifest, feed)
feed.write_text(xml.replace("<sparkle:channel>beta</sparkle:channel>", ""), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "default/non-beta"):
APPCAST.verify(manifest, feed)
if __name__ == "__main__":
unittest.main()