test(smolmachines): cover sidecar vm launch paths
This commit is contained in:
@@ -14,6 +14,7 @@ from unittest.mock import patch
|
||||
|
||||
from bot_bottle.backend.smolmachines.sidecar_bundle import (
|
||||
BundleLaunchSpec,
|
||||
allocate_raw_host_ports,
|
||||
bundle_container_name,
|
||||
bundle_network_name,
|
||||
create_bundle_network,
|
||||
@@ -203,6 +204,15 @@ class TestEnsureBundleImage(unittest.TestCase):
|
||||
|
||||
|
||||
class TestStartBundleVm(unittest.TestCase):
|
||||
def test_allocate_raw_host_ports_returns_bindable_ports(self):
|
||||
raw_ports = allocate_raw_host_ports((9099, 9420))
|
||||
|
||||
self.assertEqual({9099, 9420}, set(raw_ports))
|
||||
for host_port in raw_ports.values():
|
||||
self.assertIsInstance(host_port, int)
|
||||
self.assertGreater(host_port, 0)
|
||||
self.assertNotEqual(raw_ports[9099], raw_ports[9420])
|
||||
|
||||
def test_creates_sidecar_vm_with_ports_volumes_and_env(self):
|
||||
calls: list[tuple[str, tuple[object, ...], dict[str, object]]] = []
|
||||
|
||||
@@ -286,6 +296,27 @@ class TestStopBundleVm(unittest.TestCase):
|
||||
stop.assert_called_once_with("bot-bottle-sidecars-demo-abc12")
|
||||
delete.assert_called_once_with("bot-bottle-sidecars-demo-abc12")
|
||||
|
||||
def test_stop_and_delete_errors_are_warnings(self):
|
||||
from bot_bottle.backend.smolmachines.smolvm import SmolvmError
|
||||
result = subprocess.CompletedProcess(
|
||||
args=[],
|
||||
returncode=1,
|
||||
stdout="",
|
||||
stderr="failed",
|
||||
)
|
||||
with patch(
|
||||
"bot_bottle.backend.smolmachines.sidecar_bundle._smolvm.machine_stop",
|
||||
side_effect=SmolvmError(["smolvm", "machine", "stop"], result),
|
||||
), patch(
|
||||
"bot_bottle.backend.smolmachines.sidecar_bundle._smolvm.machine_delete",
|
||||
side_effect=SmolvmError(["smolvm", "machine", "delete"], result),
|
||||
), patch(
|
||||
"bot_bottle.backend.smolmachines.sidecar_bundle.warn",
|
||||
) as warn:
|
||||
stop_bundle_vm("demo-abc12")
|
||||
|
||||
self.assertEqual(2, warn.call_count)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user