47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from uuid import uuid4
|
|
|
|
from kernel_consumer.main import Settings, _image_metadata, create_game_vms
|
|
|
|
|
|
class Cloud:
|
|
def __init__(self) -> None:
|
|
self.requests = []
|
|
|
|
def create_vms(self, requests):
|
|
self.requests.extend(requests)
|
|
return []
|
|
|
|
def wait_for_vms_ready(self, vms):
|
|
return vms
|
|
|
|
|
|
def test_creates_one_vm_per_team_plus_public_extra() -> None:
|
|
cloud = Cloud()
|
|
settings = Settings(
|
|
cloud_project_id="project-id",
|
|
cloud_availability_zone_id="zone-id",
|
|
cloud_availability_zone_name=None,
|
|
cloud_vm_password="Password123",
|
|
)
|
|
network = type("Network", (), {"cloud_subnet_id": "subnet-id"})()
|
|
request = {"team_count": 2}
|
|
|
|
create_game_vms(request, uuid4(), network, cloud, settings)
|
|
|
|
assert len(cloud.requests) == 3
|
|
assert [item.subnets[0]["new_floating_ip"] for item in cloud.requests] == [False, False, True]
|
|
assert all(item.subnets[0]["subnet_id"] == "subnet-id" for item in cloud.requests)
|
|
assert all(item.availability_zone_id == "zone-id" for item in cloud.requests)
|
|
assert all(item.availability_zone_name is None for item in cloud.requests)
|
|
|
|
|
|
def test_rejects_password_without_uppercase_latin_letter() -> None:
|
|
settings = Settings(cloud_vm_password="lowercase123")
|
|
|
|
try:
|
|
_image_metadata(settings, "game-host")
|
|
except ValueError as error:
|
|
assert str(error) == "CLOUD_VM_PASSWORD must contain at least one uppercase Latin letter"
|
|
else:
|
|
raise AssertionError("expected invalid password to be rejected")
|