mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
feat(multiplayer): expose server shutdown acknowledgement
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
func TestServerShutdownSQLUsesIdempotencyLockAndAudit(t *testing.T) {
|
||||
checks := map[string][]string{
|
||||
"insert": {"idempotency_keys", "ON CONFLICT (scope, idempotency_key) DO NOTHING", "payload_digest"},
|
||||
"select": {"scope = $1", "idempotency_key = $2", "FOR UPDATE"},
|
||||
"match": {"match_id = $1", "server_id = $2", "FOR UPDATE"},
|
||||
"audit": {"SERVER_SHUTDOWN", "request_id", "metadata"},
|
||||
}
|
||||
queries := map[string]string{"insert": ServerShutdownIdempotencyInsertSQL, "select": ServerShutdownIdempotencySelectSQL, "match": ServerShutdownMatchLockSQL, "audit": ServerShutdownAuditSQL}
|
||||
for name, fragments := range checks {
|
||||
for _, fragment := range fragments {
|
||||
if !strings.Contains(queries[name], fragment) {
|
||||
t.Fatalf("%s query missing %q: %s", name, fragment, queries[name])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordServerShutdownRejectsInvalidArguments(t *testing.T) {
|
||||
binding := domain.WorkloadBinding{MatchID: "match-1", ServerID: "server-1"}
|
||||
now := time.Unix(1000, 0).UTC()
|
||||
for name, values := range map[string][2]string{
|
||||
"missing reason": {"", "shutdown-key-123456"},
|
||||
"short key": {"planned", "short"},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if err := RecordServerShutdown(context.Background(), (*sql.DB)(nil), binding, values[0], values[1], now); err == nil {
|
||||
t.Fatal("expected validation error")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user