mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 16:53:45 +00:00
32 lines
1011 B
Go
32 lines
1011 B
Go
package store
|
|
|
|
import "testing"
|
|
|
|
func TestResultSQLPreservesReceiptConflictAndAtomicCommitBoundaries(t *testing.T) {
|
|
checks := map[string][]string{
|
|
ResultReceiptInsertSQL: {"ON CONFLICT DO NOTHING", "payload_digest", "integrity_state"},
|
|
ResultReceiptSelectSQL: {"FOR UPDATE", "committed_at"},
|
|
ResultCommitLockSQL: {"server_id = $2", "FOR UPDATE"},
|
|
ResultMatchCompleteSQL: {"state = 'RESULT_PENDING'", "revision = revision + 1"},
|
|
ResultReceiptCommitSQL: {"COALESCE(committed_at", "committed_at"},
|
|
ResultOutboxSQL: {"match_completed", "aggregate_id", "revision"},
|
|
RatingLockSQL: {"ORDER BY player_id", "FOR UPDATE"},
|
|
}
|
|
for query, fragments := range checks {
|
|
for _, fragment := range fragments {
|
|
if !contains(query, fragment) {
|
|
t.Fatalf("query %q missing %q", query, fragment)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func contains(value, fragment string) bool {
|
|
for i := 0; i+len(fragment) <= len(value); i++ {
|
|
if value[i:i+len(fragment)] == fragment {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|