test: expand offline multiplayer failure matrix

This commit is contained in:
Josh Creek
2026-08-31 23:01:34 +01:00
parent fcc5d82763
commit d77563147c
2 changed files with 55 additions and 1 deletions
+54
View File
@@ -36,3 +36,57 @@ func TestFakeAllocatorCanForceFailureWithoutCloudState(t *testing.T) {
t.Fatalf("forced failure = %v", err)
}
}
func TestOfflineFakesCoverVerificationAndAllocationFailureMatrix(t *testing.T) {
now := time.Unix(1000, 0)
fakeSteam, err := NewFakeSteamVerifier(480)
if err != nil {
t.Fatal(err)
}
fakeSteam.Identities["steam-good"] = "player-good"
tests := []struct {
name string
ticket domain.SteamTicket
wantOK bool
}{
{name: "unknown identity", ticket: domain.SteamTicket{TicketID: "ticket-unknown", SteamID: "steam-unknown", AppID: 480, ExpiresAt: now.Add(time.Minute)}},
{name: "wrong app", ticket: domain.SteamTicket{TicketID: "ticket-wrong-app", SteamID: "steam-good", AppID: 481, ExpiresAt: now.Add(time.Minute)}},
{name: "expired", ticket: domain.SteamTicket{TicketID: "ticket-expired", SteamID: "steam-good", AppID: 480, ExpiresAt: now}},
{name: "valid", ticket: domain.SteamTicket{TicketID: "ticket-valid", SteamID: "steam-good", AppID: 480, ExpiresAt: now.Add(time.Minute)}, wantOK: true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
identity, verifyErr := fakeSteam.Verify(test.ticket, now)
if (verifyErr == nil) != test.wantOK {
t.Fatalf("identity = %+v err = %v", identity, verifyErr)
}
})
}
if _, err := fakeSteam.Verify(tests[3].ticket, now); err == nil {
t.Fatal("valid Steam ticket replay was accepted")
}
fakeAllocator, err := NewFakeAllocator([]domain.ReadyServer{{ServerID: "server-eu", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet", State: domain.ServerReady}})
if err != nil {
t.Fatal(err)
}
base := domain.AllocationRequest{AllocationID: "allocation-1234567890123456", MatchID: "match-1234567890123456", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}
if _, err := fakeAllocator.Allocate(base, now); err != nil {
t.Fatal(err)
}
if _, err := fakeAllocator.Allocate(base, now); err != nil {
t.Fatalf("identical allocation replay failed: %v", err)
}
conflict := base
conflict.Transport = "steam_sdr"
if _, err := fakeAllocator.Allocate(conflict, now); err == nil {
t.Fatal("allocation key reuse with changed compatibility was accepted")
}
noCapacity := base
noCapacity.AllocationID = "allocation-no-capacity-123456"
noCapacity.MatchID = "match-no-capacity-123456"
noCapacity.Region = "NA"
if _, err := fakeAllocator.Allocate(noCapacity, now); err != domain.ErrNoCapacity {
t.Fatalf("no-capacity error = %v", err)
}
}