forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringutils_test.go
34 lines (28 loc) · 893 Bytes
/
stringutils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package testutil // import "github.com/docker/docker/testutil"
import (
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func testLengthHelper(generator func(int) string, t *testing.T) {
expectedLength := 20
s := generator(expectedLength)
assert.Check(t, is.Equal(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.Check(t, is.Equal(64, len(str)))
_, ok := set[str]
assert.Check(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)
}