fix: flaky RandomSuffix test + CORS allow-list on public gateway #7

Merged
developer merged 2 commits from feature/cors-and-flaky-test into development 2026-05-15 06:35:59 +00:00
Showing only changes of commit 7bce67462c - Show all commits
+16 -4
View File
@@ -282,12 +282,24 @@ func TestAppendRandomSuffixGenerator(t *testing.T) {
} }
func TestRandomSuffixGenerator(t *testing.T) { func TestRandomSuffixGenerator(t *testing.T) {
var last string // The generator draws from a ~10 000 element space (Intn(9999)
for range 100 { // formatted as four digits). Comparing each sample against the
// previous one with NotEqual flaked ~1 % per 100-iteration run on
// natural collisions. Count unique values instead — if the
// generator ever gets stuck on a tiny range we still catch it,
// without depending on the birthday paradox not firing today.
const samples = 200
seen := make(map[string]struct{}, samples)
for range samples {
s := util.RandomSuffixGenerator() s := util.RandomSuffixGenerator()
assert.Len(t, s, 4) assert.Len(t, s, 4)
assert.NotEqual(t, last, s)
assert.True(t, strings.ContainsFunc(s, func(r rune) bool { return r >= '0' && r <= '9' })) assert.True(t, strings.ContainsFunc(s, func(r rune) bool { return r >= '0' && r <= '9' }))
last = s seen[s] = struct{}{}
} }
// In 200 draws from ~10 000 the expected number of unique values
// is ~198; a stuck generator (single value) would land at 1, a
// 256-value range at ~196. 150 is well above the floor either
// way and well below the expected mean.
assert.GreaterOrEqual(t, len(seen), 150,
"RandomSuffixGenerator drew from too small a range over %d samples", samples)
} }