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{}{} } }