import urllib.request
import json
import sys

# Test health
try:
    res = urllib.request.urlopen("http://127.0.0.1:18080/health", timeout=3)
    data = json.loads(res.read().decode('utf-8'))
    print("health_status=", data)
except Exception as e:
    print("health_error=", repr(e))
    sys.exit(1)

# Test token
try:
    res = urllib.request.urlopen("http://127.0.0.1:18080/token?room=gate7n-b-room&identity=browser-mic-user", timeout=3)
    data = json.loads(res.read().decode('utf-8'))
    print("token_keys=", sorted(data.keys()))
    print("token_url=", data.get("url"))
    print("token_room=", data.get("room"))
    print("token_identity=", data.get("identity"))
    print("token_len=", len(data.get("token", "")))
except Exception as e:
    print("token_error=", repr(e))
    sys.exit(1)
