From 5d90b564afb4c87277105388af11943edfe4041d Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 21 Sep 2026 01:30:46 +0000 Subject: [PATCH] Add multiplayer server main_test.go --- server/main_test.go | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 server/main_test.go diff --git a/server/main_test.go b/server/main_test.go new file mode 100644 index 0000000..8c2d70d --- /dev/null +++ b/server/main_test.go @@ -0,0 +1,50 @@ +package main + +import ( + "math" + "testing" +) + +func TestTicketSingleUse(t *testing.T) { + store := newTicketStore() + value, err := store.issue("player-1", "Dave") + if err != nil { + t.Fatal(err) + } + if item, ok := store.consume(value); !ok || item.Subject != "player-1" { + t.Fatalf("first consume failed: %#v %v", item, ok) + } + if _, ok := store.consume(value); ok { + t.Fatal("ticket must be one-time") + } +} + +func TestTransformSanitizers(t *testing.T) { + if got := clampFloat(-5, 0, 3600); got != 0 { + t.Fatalf("clamp low=%v", got) + } + if got := clampFloat(4000, 0, 3600); got != 3600 { + t.Fatalf("clamp high=%v", got) + } + if got := clampFloat(math.NaN(), 0, 3600); got != 0 { + t.Fatalf("nan=%v", got) + } + if got := normalizeAngle(-90); got != 270 { + t.Fatalf("angle=%v", got) + } + if got := clampInt(900, 0, 500); got != 500 { + t.Fatalf("hull=%v", got) + } +} + +func TestAudienceMatch(t *testing.T) { + if !audienceMatches(claims{AuthorizedParty: "airship-web"}, "airship-web") { + t.Fatal("azp should match") + } + if !audienceMatches(claims{Audience: []interface{}{"account", "airship-web"}}, "airship-web") { + t.Fatal("aud should match") + } + if audienceMatches(claims{AuthorizedParty: "other"}, "airship-web") { + t.Fatal("wrong client must not match") + } +}