mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 13:03:12 +00:00
113 lines
3.8 KiB
Python
113 lines
3.8 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Tests for require_commit_checks.classify_checks."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import unittest
|
||
|
|
|
||
|
|
from require_commit_checks import classify_checks
|
||
|
|
|
||
|
|
|
||
|
|
class ClassifyChecksTests(unittest.TestCase):
|
||
|
|
def test_success(self) -> None:
|
||
|
|
state, _ = classify_checks(
|
||
|
|
[
|
||
|
|
{"name": "Build and test", "status": "completed", "conclusion": "success"},
|
||
|
|
{"name": "architecture", "status": "completed", "conclusion": "success"},
|
||
|
|
]
|
||
|
|
)
|
||
|
|
self.assertEqual(state, "success")
|
||
|
|
|
||
|
|
def test_pending_missing(self) -> None:
|
||
|
|
state, details = classify_checks(
|
||
|
|
[
|
||
|
|
{"name": "Build and test", "status": "completed", "conclusion": "success"},
|
||
|
|
]
|
||
|
|
)
|
||
|
|
self.assertEqual(state, "pending")
|
||
|
|
self.assertTrue(any("architecture" in line for line in details))
|
||
|
|
|
||
|
|
def test_pending_in_progress(self) -> None:
|
||
|
|
state, _ = classify_checks(
|
||
|
|
[
|
||
|
|
{"name": "Build and test", "status": "in_progress", "conclusion": None},
|
||
|
|
{"name": "architecture", "status": "completed", "conclusion": "success"},
|
||
|
|
]
|
||
|
|
)
|
||
|
|
self.assertEqual(state, "pending")
|
||
|
|
|
||
|
|
def test_failure(self) -> None:
|
||
|
|
state, _ = classify_checks(
|
||
|
|
[
|
||
|
|
{"name": "Build and test", "status": "completed", "conclusion": "failure"},
|
||
|
|
{"name": "architecture", "status": "completed", "conclusion": "success"},
|
||
|
|
]
|
||
|
|
)
|
||
|
|
self.assertEqual(state, "failure")
|
||
|
|
|
||
|
|
def test_latest_rerun_success_wins_over_older_failure(self) -> None:
|
||
|
|
state, _ = classify_checks(
|
||
|
|
[
|
||
|
|
{
|
||
|
|
"name": "Build and test",
|
||
|
|
"id": 1,
|
||
|
|
"started_at": "2026-09-16T12:00:00Z",
|
||
|
|
"completed_at": "2026-09-16T12:05:00Z",
|
||
|
|
"status": "completed",
|
||
|
|
"conclusion": "failure",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"name": "Build and test",
|
||
|
|
"id": 3,
|
||
|
|
"started_at": "2026-09-16T12:10:00Z",
|
||
|
|
"completed_at": "2026-09-16T12:12:00Z",
|
||
|
|
"status": "completed",
|
||
|
|
"conclusion": "success",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"name": "architecture",
|
||
|
|
"id": 2,
|
||
|
|
"started_at": "2026-09-16T12:00:00Z",
|
||
|
|
"completed_at": "2026-09-16T12:04:00Z",
|
||
|
|
"status": "completed",
|
||
|
|
"conclusion": "success",
|
||
|
|
},
|
||
|
|
]
|
||
|
|
)
|
||
|
|
self.assertEqual(state, "success")
|
||
|
|
|
||
|
|
def test_latest_rerun_failure_wins_over_older_success(self) -> None:
|
||
|
|
state, _ = classify_checks(
|
||
|
|
[
|
||
|
|
{
|
||
|
|
"name": "architecture",
|
||
|
|
"id": 9,
|
||
|
|
"started_at": "2026-09-16T13:00:00Z",
|
||
|
|
"completed_at": "2026-09-16T13:02:00Z",
|
||
|
|
"status": "completed",
|
||
|
|
"conclusion": "failure",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"name": "architecture",
|
||
|
|
"id": 4,
|
||
|
|
"started_at": "2026-09-16T12:00:00Z",
|
||
|
|
"completed_at": "2026-09-16T12:01:00Z",
|
||
|
|
"status": "completed",
|
||
|
|
"conclusion": "success",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"name": "Build and test",
|
||
|
|
"id": 5,
|
||
|
|
"started_at": "2026-09-16T12:00:00Z",
|
||
|
|
"completed_at": "2026-09-16T12:03:00Z",
|
||
|
|
"status": "completed",
|
||
|
|
"conclusion": "success",
|
||
|
|
},
|
||
|
|
]
|
||
|
|
)
|
||
|
|
self.assertEqual(state, "failure")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|