mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
52ee181042
With the Fleet readiness wait corrected, the gate reached the allocation
check for the first time and failed with "allocation did not return a
GameServer" -- while the cluster dump shows the allocation plainly
succeeded: one GameServer Allocated, Fleet reporting ALLOCATED 1.
GameServerAllocationStatus is flat: state, gameServerName, address,
ports, nodeName. It does not embed the allocated GameServer. The
validator read status.gameServer.metadata.name and
status.gameServer.status.{address,ports}, a shape Agones never sends,
and its unit tests asserted that same invented shape -- so validator and
tests agreed with each other while both disagreed with Agones. Nothing
caught it because the gate had never once allocated anything.
Read the real fields, keeping every existing check: non-empty name,
address neither blank nor unspecified, exactly one named "game" port in
range.
Also print the response body when validation fails. work_dir is removed
by the EXIT trap, so a shape mismatch was otherwise invisible from CI --
which is how this survived. If the shape is still not what I expect, the
next run says so instead of costing another round trip.
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from verify_agones_allocation_response import validate_allocation
|
|
|
|
|
|
def response(**overrides):
|
|
document = {
|
|
# Mirrors Agones' real GameServerAllocationStatus, which is flat.
|
|
# These fixtures previously encoded a nested "gameServer" object that
|
|
# Agones never returns, so the suite agreed with the validator while
|
|
# both disagreed with reality.
|
|
"status": {
|
|
"state": "Allocated",
|
|
"gameServerName": "cosmic-clash-game-abc",
|
|
"address": "10.0.0.7",
|
|
"ports": [{"name": "game", "port": 31001}],
|
|
}
|
|
}
|
|
document["status"].update(overrides)
|
|
return document
|
|
|
|
|
|
class AgonesAllocationResponseTest(unittest.TestCase):
|
|
def test_accepts_allocated_game_server_with_named_udp_port(self):
|
|
self.assertEqual(validate_allocation(response()), ("cosmic-clash-game-abc", 31001))
|
|
|
|
def test_rejects_non_allocated_state(self):
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(response(state="Ready"))
|
|
|
|
def test_rejects_missing_identity_or_address(self):
|
|
missing_name = response()
|
|
missing_name["status"]["gameServerName"] = ""
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(missing_name)
|
|
|
|
missing_address = response()
|
|
missing_address["status"]["address"] = "0.0.0.0"
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(missing_address)
|
|
|
|
def test_rejects_ambiguous_or_invalid_game_ports(self):
|
|
duplicate = response()
|
|
duplicate["status"]["ports"].append({"name": "game", "port": 31002})
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(duplicate)
|
|
|
|
wrong_name = response()
|
|
wrong_name["status"]["ports"] = [{"name": "query", "port": 31001}]
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(wrong_name)
|
|
|
|
invalid_port = response()
|
|
invalid_port["status"]["ports"][0]["port"] = 70000
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(invalid_port)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|