mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
65 lines
2.1 KiB
Python
65 lines
2.1 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 = {
|
|
"status": {
|
|
"state": "Allocated",
|
|
"gameServer": {
|
|
"metadata": {"name": "cosmic-clash-game-abc"},
|
|
"status": {
|
|
"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"]["gameServer"]["metadata"] = {}
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(missing_name)
|
|
|
|
missing_address = response()
|
|
missing_address["status"]["gameServer"]["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"]["gameServer"]["status"]["ports"].append({"name": "game", "port": 31002})
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(duplicate)
|
|
|
|
wrong_name = response()
|
|
wrong_name["status"]["gameServer"]["status"]["ports"] = [{"name": "query", "port": 31001}]
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(wrong_name)
|
|
|
|
invalid_port = response()
|
|
invalid_port["status"]["gameServer"]["status"]["ports"][0]["port"] = 70000
|
|
with self.assertRaises(ValueError):
|
|
validate_allocation(invalid_port)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|