Refactor pkg/common, Fixes #11599

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
Antonio Murdaca 2015-03-24 12:25:26 +01:00
parent 6a6ba3da1d
commit 4dd569ee0f
7 changed files with 97 additions and 60 deletions

View file

@ -0,0 +1,25 @@
package stringutils
import "testing"
func TestRandomString(t *testing.T) {
str := GenerateRandomString()
if len(str) != 64 {
t.Fatalf("Id returned is incorrect: %s", str)
}
}
func TestRandomStringUniqueness(t *testing.T) {
repeats := 25
set := make(map[string]struct{}, repeats)
for i := 0; i < repeats; i = i + 1 {
str := GenerateRandomString()
if len(str) != 64 {
t.Fatalf("Id returned is incorrect: %s", str)
}
if _, ok := set[str]; ok {
t.Fatalf("Random number is repeated")
}
set[str] = struct{}{}
}
}