mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Generate shorter UIDs (#79843)
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"cuelang.org/go/pkg/strings"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/teris-io/shortid"
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
)
|
||||
|
||||
@@ -48,14 +49,27 @@ func TestRandomUIDs(t *testing.T) {
|
||||
t.Fatalf("created invalid name: %v", validation)
|
||||
}
|
||||
|
||||
_, err := uuid.Parse(v)
|
||||
require.NoError(t, err)
|
||||
|
||||
//fmt.Println(v)
|
||||
// fmt.Println(v)
|
||||
}
|
||||
// t.FailNow()
|
||||
}
|
||||
|
||||
func TestCaseInsensitiveCollisionsUIDs(t *testing.T) {
|
||||
history := make(map[string]bool, 0)
|
||||
for i := 0; i < 100000; i++ {
|
||||
v := GenerateShortUID()
|
||||
if false {
|
||||
v, _ = shortid.Generate() // collides in less then 500 iterations
|
||||
}
|
||||
|
||||
lower := strings.ToLower(v)
|
||||
_, exists := history[lower]
|
||||
require.False(t, exists, fmt.Sprintf("already found: %s (index:%d)", v, i))
|
||||
|
||||
history[lower] = true
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsShortUIDTooLong(t *testing.T) {
|
||||
var tests = []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user