e9ecc4c1f7
CI / test (pull_request) Successful in 2m13s
Fix goroutine-unsafe ULID entropy by wrapping in LockedMonotonicReader. Move PRAGMA foreign_keys outside transaction in v3 migration where SQLite was silently ignoring it. Escape LIKE wildcards in link resolution to prevent false matches. Add non-localhost binding warning, log writeJSON encoder errors, add ?permanent=true for explicit hard delete, preserve title/description during absorb, use millisecond backup timestamps, add path.Clean to spaHandler. Frontend gains checkedJSON() for resp.ok validation, consistent stopPropagation, and shared renderCardSections() to eliminate duplicate rendering.
52 lines
877 B
Go
52 lines
877 B
Go
package ulid
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestNew_ReturnsValidULID(t *testing.T) {
|
|
id := New()
|
|
if len(id) != 26 {
|
|
t.Errorf("expected 26 chars, got %d: %s", len(id), id)
|
|
}
|
|
}
|
|
|
|
func TestNew_Unique(t *testing.T) {
|
|
a := New()
|
|
b := New()
|
|
if a == b {
|
|
t.Errorf("two calls returned same ULID: %s", a)
|
|
}
|
|
}
|
|
|
|
func TestNew_Sortable(t *testing.T) {
|
|
a := New()
|
|
b := New()
|
|
if b < a {
|
|
t.Errorf("expected b >= a for sequential calls: a=%s b=%s", a, b)
|
|
}
|
|
}
|
|
|
|
func TestNew_ConcurrentUnique(t *testing.T) {
|
|
const n = 100
|
|
ids := make([]string, n)
|
|
var wg sync.WaitGroup
|
|
wg.Add(n)
|
|
for i := 0; i < n; i++ {
|
|
go func(idx int) {
|
|
defer wg.Done()
|
|
ids[idx] = New()
|
|
}(i)
|
|
}
|
|
wg.Wait()
|
|
|
|
seen := make(map[string]struct{}, n)
|
|
for _, id := range ids {
|
|
if _, dup := seen[id]; dup {
|
|
t.Fatalf("duplicate ULID under concurrency: %s", id)
|
|
}
|
|
seen[id] = struct{}{}
|
|
}
|
|
}
|