mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
b37c214e3c
This was done with something along the lines of: ``` mv internal/test testutil pushd testutil/; grep -IRl "package test" | xargs -I '{}' sed -i -e 's|package test|package testutil|g' {}; popd mv internal/testutil/*.go testutil/ && rm -rf internal/ grep -IRl "github.com\/docker\/docker\/internal\/test" | xargs -I '{}' sed -i -e 's|github.com/docker/docker/internal/test|github.com/docker/docker/test|g' {} goimports . ``` I also modified the basic plugin path in testutil/fixtures/plugin. Signed-off-by: Sam Whited <sam@samwhited.com>
34 lines
887 B
Go
34 lines
887 B
Go
package testutil // import "github.com/docker/docker/testutil"
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gotest.tools/assert"
|
|
is "gotest.tools/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)
|
|
}
|