weiro/models/ids_test.go

35 lines
569 B
Go
Raw Permalink Normal View History

package models
import (
"testing"
)
func TestNewNanoID(t *testing.T) {
id := NewNanoID()
if len(id) != 12 {
t.Errorf("Expected ID length of 12, got %d", len(id))
}
if id == "" {
t.Error("Expected non-empty ID")
}
}
func TestNewNanoID_Uniqueness(t *testing.T) {
ids := make(map[string]bool)
iterations := 1000
for i := 0; i < iterations; i++ {
id := NewNanoID()
if ids[id] {
t.Errorf("Duplicate ID generated: %s", id)
}
ids[id] = true
}
if len(ids) != iterations {
t.Errorf("Expected %d unique IDs, got %d", iterations, len(ids))
}
}