test makefiles: add --seed flag and make data generated repeatable #5214

This commit is contained in:
Nick Craig-Wood 2021-04-10 13:42:17 +01:00
parent 813bf029d4
commit 60dcafe04d
2 changed files with 26 additions and 10 deletions

View file

@ -10,10 +10,11 @@ import (
"github.com/pkg/errors"
)
// String create a random string for test purposes.
// StringFn create a random string for test purposes using the random
// number generator function passed in.
//
// Do not use these for passwords.
func String(n int) string {
func StringFn(n int, randIntn func(n int) int) string {
const (
vowel = "aeiou"
consonant = "bcdfghjklmnpqrstvwxyz"
@ -25,11 +26,18 @@ func String(n int) string {
for i := range out {
source := pattern[p]
p = (p + 1) % len(pattern)
out[i] = source[mathrand.Intn(len(source))]
out[i] = source[randIntn(len(source))]
}
return string(out)
}
// String create a random string for test purposes.
//
// Do not use these for passwords.
func String(n int) string {
return StringFn(n, mathrand.Intn)
}
// Password creates a crypto strong password which is just about
// memorable. The password is composed of printable ASCII characters
// from the base64 alphabet.