github.com/jaegerpicker/docker@v0.7.7-0.20150325003727-22dba32b4dab/pkg/stringutils/stringutils_test.go (about)

     1  package stringutils
     2  
     3  import "testing"
     4  
     5  func TestRandomString(t *testing.T) {
     6  	str := GenerateRandomString()
     7  	if len(str) != 64 {
     8  		t.Fatalf("Id returned is incorrect: %s", str)
     9  	}
    10  }
    11  
    12  func TestRandomStringUniqueness(t *testing.T) {
    13  	repeats := 25
    14  	set := make(map[string]struct{}, repeats)
    15  	for i := 0; i < repeats; i = i + 1 {
    16  		str := GenerateRandomString()
    17  		if len(str) != 64 {
    18  			t.Fatalf("Id returned is incorrect: %s", str)
    19  		}
    20  		if _, ok := set[str]; ok {
    21  			t.Fatalf("Random number is repeated")
    22  		}
    23  		set[str] = struct{}{}
    24  	}
    25  }