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,49 @@
|
||||
// Package testkit provides deterministic offline collaborators for control
|
||||
// plane integration tests. It contains no network or Steam/cloud dependency.
|
||||
package testkit
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
type FakeSteamVerifier struct {
|
||||
Verifier *domain.TicketVerifier
|
||||
Identities map[string]string
|
||||
}
|
||||
|
||||
func NewFakeSteamVerifier(appID uint64) (*FakeSteamVerifier, error) {
|
||||
verifier, err := domain.NewTicketVerifier(appID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FakeSteamVerifier{Verifier: verifier, Identities: make(map[string]string)}, nil
|
||||
}
|
||||
|
||||
func (f *FakeSteamVerifier) Verify(ticket domain.SteamTicket, now time.Time) (domain.VerifiedIdentity, error) {
|
||||
return f.Verifier.Verify(ticket, func(steamID string) (string, bool) {
|
||||
playerID, ok := f.Identities[steamID]
|
||||
return playerID, ok
|
||||
}, now)
|
||||
}
|
||||
|
||||
type FakeAllocator struct {
|
||||
Allocator *domain.Allocator
|
||||
ForcedError error
|
||||
}
|
||||
|
||||
func NewFakeAllocator(servers []domain.ReadyServer) (*FakeAllocator, error) {
|
||||
allocator, err := domain.NewAllocator(servers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &FakeAllocator{Allocator: allocator}, nil
|
||||
}
|
||||
|
||||
func (f *FakeAllocator) Allocate(request domain.AllocationRequest, now time.Time) (domain.Allocation, error) {
|
||||
if f.ForcedError != nil {
|
||||
return domain.Allocation{}, f.ForcedError
|
||||
}
|
||||
return f.Allocator.Allocate(request, now)
|
||||
}
|
||||
Reference in New Issue
Block a user