github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/internal/testutil/stringutils_test.go (about)

     1  package testutil
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func testLengthHelper(generator func(int) string, t *testing.T) {
    10  	expectedLength := 20
    11  	s := generator(expectedLength)
    12  	assert.Equal(t, expectedLength, len(s))
    13  }
    14  
    15  func testUniquenessHelper(generator func(int) string, t *testing.T) {
    16  	repeats := 25
    17  	set := make(map[string]struct{}, repeats)
    18  	for i := 0; i < repeats; i = i + 1 {
    19  		str := generator(64)
    20  		assert.Equal(t, 64, len(str))
    21  		_, ok := set[str]
    22  		assert.False(t, ok, "Random number is repeated")
    23  		set[str] = struct{}{}
    24  	}
    25  }
    26  
    27  func TestGenerateRandomAlphaOnlyStringLength(t *testing.T) {
    28  	testLengthHelper(GenerateRandomAlphaOnlyString, t)
    29  }
    30  
    31  func TestGenerateRandomAlphaOnlyStringUniqueness(t *testing.T) {
    32  	testUniquenessHelper(GenerateRandomAlphaOnlyString, t)
    33  }