mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
feat: persist player-scoped assignments
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAssignmentSQLBindsPlayerAndPreservesIdenticalReplay(t *testing.T) {
|
||||
for query, fragments := range map[string][]string{
|
||||
AssignmentUpsertSQL: {"ON CONFLICT (match_id, player_id)", "WHERE assignments.allocation_id = EXCLUDED.allocation_id", "join_authorisation", "manifest_digest"},
|
||||
AssignmentSelectSQL: {"match_id = $1", "player_id = $2", "expires_at > $3"},
|
||||
} {
|
||||
for _, fragment := range fragments {
|
||||
if !contains(query, fragment) {
|
||||
t.Fatalf("query %q missing %q", query, fragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignmentStoreRejectsInvalidRecoveryAndManifestInputs(t *testing.T) {
|
||||
if _, err := GetAssignment(nil, nil, "player-1", "match-1", time.Unix(1000, 0)); err == nil {
|
||||
t.Fatal("nil database accepted")
|
||||
}
|
||||
if err := SaveAssignment(nil, nil, DurableAssignment{MatchID: "match-1", PlayerID: "player-1", ExpiresAt: time.Unix(1000, 0)}); err == nil {
|
||||
t.Fatal("incomplete assignment accepted")
|
||||
}
|
||||
if err := validateDurableAssignment(DurableAssignment{MatchID: "match-1", PlayerID: "player-1", AllocationID: "allocation-1", ServerID: "server-1", Slot: 6, Region: "EU", ClientBuild: "build-1", ProtocolVersion: 1, Transport: "enet", Endpoint: "127.0.0.1:1", JoinAuthorisation: "join", ManifestDigest: []byte("digest"), ExpiresAt: time.Unix(1001, 0)}); err == nil {
|
||||
t.Fatal("out-of-range slot accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user