2019-08-29 16:52:40 -04:00
|
|
|
package testutil // import "github.com/docker/docker/testutil"
|
2017-10-27 20:28:19 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-10-27 20:28:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func testLengthHelper(generator func(int) string, t *testing.T) {
|
|
|
|
expectedLength := 20
|
|
|
|
s := generator(expectedLength)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(expectedLength, len(s)))
|
2017-10-27 20:28:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(64, len(str)))
|
2017-10-27 20:28:19 -04:00
|
|
|
_, ok := set[str]
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, !ok, "Random number is repeated")
|
2017-10-27 20:28:19 -04:00
|
|
|
set[str] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenerateRandomAlphaOnlyStringLength(t *testing.T) {
|
|
|
|
testLengthHelper(GenerateRandomAlphaOnlyString, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenerateRandomAlphaOnlyStringUniqueness(t *testing.T) {
|
|
|
|
testUniquenessHelper(GenerateRandomAlphaOnlyString, t)
|
|
|
|
}
|