open-vault/sdk/helper/base62/base62_test.go

32 lines
489 B
Go
Raw Normal View History

2019-04-15 15:36:10 +00:00
package base62
import (
"testing"
)
func TestRandom(t *testing.T) {
strings := make(map[string]struct{})
for i := 0; i < 100000; i++ {
c, err := Random(16)
if err != nil {
t.Fatal(err)
}
if _, ok := strings[c]; ok {
t.Fatalf("Unexpected duplicate string: %s", c)
}
strings[c] = struct{}{}
}
for i := 0; i < 3000; i++ {
c, err := Random(i)
if err != nil {
t.Fatal(err)
}
if len(c) != i {
t.Fatalf("Expected length %d, got: %d", i, len(c))
}
}
}