test(backend): cover poll_ca_cert timeout paths for diff-coverage gate
test / integration-docker (pull_request) Successful in 12s
tracker-policy-pr / check-pr (pull_request) Successful in 10s
test / unit (pull_request) Successful in 35s
test / stage-firecracker-inputs (pull_request) Successful in 2s
test / build-infra (pull_request) Successful in 3m37s
test / integration-firecracker (pull_request) Successful in 1m30s
test / coverage (pull_request) Successful in 1m32s
test / publish-infra (pull_request) Has been skipped
test / integration-docker (push) Successful in 13s
prd-number / assign-numbers (push) Failing after 19s
lint / lint (push) Successful in 43s
Update Quality Badges / update-badges (push) Failing after 41s
test / unit (push) Successful in 1m42s
test / stage-firecracker-inputs (push) Successful in 2s
test / build-infra (push) Failing after 7s
test / integration-firecracker (push) Has been skipped
test / coverage (push) Has been skipped
test / publish-infra (push) Has been skipped
test / integration-docker (pull_request) Successful in 12s
tracker-policy-pr / check-pr (pull_request) Successful in 10s
test / unit (pull_request) Successful in 35s
test / stage-firecracker-inputs (pull_request) Successful in 2s
test / build-infra (pull_request) Successful in 3m37s
test / integration-firecracker (pull_request) Successful in 1m30s
test / coverage (pull_request) Successful in 1m32s
test / publish-infra (pull_request) Has been skipped
test / integration-docker (push) Successful in 13s
prd-number / assign-numbers (push) Failing after 19s
lint / lint (push) Successful in 43s
Update Quality Badges / update-badges (push) Failing after 41s
test / unit (push) Successful in 1m42s
test / stage-firecracker-inputs (push) Successful in 2s
test / build-infra (push) Failing after 7s
test / integration-firecracker (push) Has been skipped
test / coverage (push) Has been skipped
test / publish-infra (push) Has been skipped
Add tests for the three uncovered paths introduced by the poll_ca_cert extraction: the timeout + sleep branches in backend/util, and the TimeoutError → GatewayError and TimeoutError → die() conversions in the macOS and Firecracker callers.
This commit was merged in pull request #432.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Unit: shared cross-backend helpers in backend/util.py."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from bot_bottle.backend import util as backend_util
|
||||
|
||||
|
||||
class TestPollCaCert(unittest.TestCase):
|
||||
def test_returns_pem_on_first_success(self) -> None:
|
||||
result = backend_util.poll_ca_cert(lambda: "PEM", timeout=1.0)
|
||||
self.assertEqual("PEM", result)
|
||||
|
||||
def test_raises_timeout_error_when_cert_never_appears(self) -> None:
|
||||
with self.assertRaises(TimeoutError):
|
||||
backend_util.poll_ca_cert(lambda: None, timeout=0.0)
|
||||
|
||||
def test_polls_until_cert_appears(self) -> None:
|
||||
responses = iter([None, None, "-----BEGIN CERTIFICATE-----\n"])
|
||||
with patch("bot_bottle.backend.util.time.sleep") as mock_sleep:
|
||||
result = backend_util.poll_ca_cert(lambda: next(responses), timeout=5.0)
|
||||
self.assertTrue(result.startswith("-----BEGIN CERTIFICATE-----"))
|
||||
self.assertEqual(2, mock_sleep.call_count)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user