mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
test: add offline Steam and allocator fakes
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package testkit
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
func TestFakeSteamVerifierIsDeterministicAndOffline(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
fake, err := NewFakeSteamVerifier(480)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fake.Identities["steam-1"] = "player-1"
|
||||
ticket := domain.SteamTicket{TicketID: "ticket-1", SteamID: "steam-1", AppID: 480, ExpiresAt: now.Add(time.Minute)}
|
||||
identity, err := fake.Verify(ticket, now)
|
||||
if err != nil || identity.PlayerID != "player-1" {
|
||||
t.Fatalf("identity = %+v err=%v", identity, err)
|
||||
}
|
||||
if _, err := fake.Verify(ticket, now); err == nil {
|
||||
t.Fatal("fake accepted ticket replay")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFakeAllocatorCanForceFailureWithoutCloudState(t *testing.T) {
|
||||
fake, err := NewFakeAllocator([]domain.ReadyServer{{ServerID: "server-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet", State: domain.ServerReady}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fake.ForcedError = errors.New("forced allocation failure")
|
||||
_, err = fake.Allocate(domain.AllocationRequest{AllocationID: "allocation-1", MatchID: "match-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}, time.Unix(1000, 0))
|
||||
if err == nil || err.Error() != "forced allocation failure" {
|
||||
t.Fatalf("forced failure = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user