mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
b80fae7356
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
25 lines
537 B
Go
25 lines
537 B
Go
package stringutils
|
|
|
|
import "testing"
|
|
|
|
func TestRandomString(t *testing.T) {
|
|
str := GenerateRandomString()
|
|
if len(str) != 64 {
|
|
t.Fatalf("Id returned is incorrect: %s", str)
|
|
}
|
|
}
|
|
|
|
func TestRandomStringUniqueness(t *testing.T) {
|
|
repeats := 25
|
|
set := make(map[string]struct{}, repeats)
|
|
for i := 0; i < repeats; i = i + 1 {
|
|
str := GenerateRandomString()
|
|
if len(str) != 64 {
|
|
t.Fatalf("Id returned is incorrect: %s", str)
|
|
}
|
|
if _, ok := set[str]; ok {
|
|
t.Fatalf("Random number is repeated")
|
|
}
|
|
set[str] = struct{}{}
|
|
}
|
|
}
|