mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
|
)
|
|
|
|
func TestServerConnectionSQLBindsWorkloadParticipantAndLiveAssignment(t *testing.T) {
|
|
for _, fragment := range []string{
|
|
"connected_at = COALESCE", "mp.participation_active", "m.server_id = $2",
|
|
"a.allocation_id = $3", "a.state = 'ALLOCATED'", "assn.player_id = mp.player_id",
|
|
"assn.expires_at > $5", "RETURNING mp.connected_at",
|
|
} {
|
|
if !strings.Contains(ServerConnectionParticipantSQL, fragment) {
|
|
t.Fatalf("connection SQL missing %q: %s", fragment, ServerConnectionParticipantSQL)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRecordPlayerConnectedRejectsInvalidArguments(t *testing.T) {
|
|
binding := domain.WorkloadBinding{AllocationID: "allocation-1", MatchID: "match-1", ServerID: "server-1"}
|
|
if err := RecordPlayerConnected(context.Background(), (*sql.DB)(nil), binding, "player-1", "connection-key-123456", time.Unix(1000, 0)); err == nil {
|
|
t.Fatal("nil database accepted")
|
|
}
|
|
if err := RecordPlayerConnected(context.Background(), &sql.DB{}, domain.WorkloadBinding{}, "player-1", "connection-key-123456", time.Unix(1000, 0)); err == nil {
|
|
t.Fatal("empty workload binding accepted")
|
|
}
|
|
}
|