mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 01:32:04 +00:00
test: expand offline multiplayer failure matrix
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user