test(ci): cover assurance gate entry points
prd-number-check / require-numbered-prds (pull_request) Successful in 7s
tracker-policy-pr / check-pr (pull_request) Successful in 8s
lint / lint (push) Successful in 58s
test / unit (pull_request) Successful in 48s
test / integration-docker (pull_request) Failing after 19m28s
test / coverage (pull_request) Has been skipped
prd-number-check / require-numbered-prds (pull_request) Successful in 7s
tracker-policy-pr / check-pr (pull_request) Successful in 8s
lint / lint (push) Successful in 58s
test / unit (pull_request) Successful in 48s
test / integration-docker (pull_request) Failing after 19m28s
test / coverage (pull_request) Has been skipped
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from contextlib import redirect_stderr, redirect_stdout
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
|
||||
from scripts.docker_host_address import default_ipv4_gateway
|
||||
from scripts.docker_host_address import default_ipv4_gateway, main
|
||||
|
||||
|
||||
class TestDefaultIpv4Gateway(unittest.TestCase):
|
||||
@@ -23,6 +26,34 @@ class TestDefaultIpv4Gateway(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "no active"):
|
||||
default_ipv4_gateway(routes)
|
||||
|
||||
def test_ignores_short_malformed_and_inactive_routes(self) -> None:
|
||||
routes = (
|
||||
"Iface Destination Gateway Flags\n"
|
||||
"short row\n"
|
||||
"eth0 00000000 nope 0003\n"
|
||||
"eth0 00000000 010011AC 0001\n"
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "no active"):
|
||||
default_ipv4_gateway(routes)
|
||||
|
||||
def test_main_prints_gateway(self) -> None:
|
||||
routes = (
|
||||
"Iface Destination Gateway Flags\n"
|
||||
"eth0 00000000 010011AC 0003\n"
|
||||
)
|
||||
output = StringIO()
|
||||
with patch("pathlib.Path.read_text", return_value=routes), \
|
||||
redirect_stdout(output):
|
||||
self.assertEqual(0, main())
|
||||
self.assertEqual("172.17.0.1\n", output.getvalue())
|
||||
|
||||
def test_main_reports_route_error(self) -> None:
|
||||
error = StringIO()
|
||||
with patch("pathlib.Path.read_text", side_effect=OSError("denied")), \
|
||||
redirect_stderr(error):
|
||||
self.assertEqual(1, main())
|
||||
self.assertIn("docker-host-address: denied", error.getvalue())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user