Files
CosmicClash/server/store/allocator_sql_test.go
T
2026-09-01 09:43:33 +01:00

33 lines
1.2 KiB
Go

package store
import (
"testing"
"time"
"github.com/cosmic-clash/cosmic-clash/server/domain"
)
func TestAllocatorSQLClaimsAndAuditsCompatibleReadyServers(t *testing.T) {
for query, fragments := range map[string][]string{
RegisterReadyServerSQL: {"game_servers", "ON CONFLICT", "state = 'READY'"},
ClaimReadyServerSQL: {"state = 'READY'", "region = $1", "protocol_version = $3", "FOR UPDATE SKIP LOCKED", "ORDER BY server_id"},
InsertAllocationSQL: {"allocations", "request_digest", "state", "ALLOCATED"},
} {
for _, fragment := range fragments {
if !contains(query, fragment) {
t.Fatalf("query missing %q", fragment)
}
}
}
}
func TestClaimAllocationRejectsInvalidRequestsWithoutDatabase(t *testing.T) {
_, err := ClaimAllocation(nil, nil, domain.AllocationRequest{AllocationID: "a", MatchID: "m", Region: "EU", Build: "b", Protocol: 1, Transport: "enet"}, time.Unix(1000, 0))
if err == nil {
t.Fatal("nil database accepted")
}
if _, err := ClaimAllocation(nil, nil, domain.AllocationRequest{AllocationID: "a", MatchID: "m", Region: "EU", Build: "b", Protocol: 0, Transport: "enet"}, time.Unix(1000, 0)); err != domain.ErrAllocationInput {
t.Fatalf("invalid request err=%v", err)
}
}