mirror of
https://github.com/genuinetools/reg.git
synced 2024-08-21 06:10:23 -04:00
34 lines
860 B
Go
34 lines
860 B
Go
package testutil // import "github.com/docker/docker/internal/testutil"
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func testLengthHelper(generator func(int) string, t *testing.T) {
|
|
expectedLength := 20
|
|
s := generator(expectedLength)
|
|
assert.Equal(t, expectedLength, len(s))
|
|
}
|
|
|
|
func testUniquenessHelper(generator func(int) string, t *testing.T) {
|
|
repeats := 25
|
|
set := make(map[string]struct{}, repeats)
|
|
for i := 0; i < repeats; i = i + 1 {
|
|
str := generator(64)
|
|
assert.Equal(t, 64, len(str))
|
|
_, ok := set[str]
|
|
assert.False(t, ok, "Random number is repeated")
|
|
set[str] = struct{}{}
|
|
}
|
|
}
|
|
|
|
func TestGenerateRandomAlphaOnlyStringLength(t *testing.T) {
|
|
testLengthHelper(GenerateRandomAlphaOnlyString, t)
|
|
}
|
|
|
|
func TestGenerateRandomAlphaOnlyStringUniqueness(t *testing.T) {
|
|
testUniquenessHelper(GenerateRandomAlphaOnlyString, t)
|
|
}
|