History

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

Nick Craig-Wood committed 5 years ago

Commit 60dcafe1 parent 813bf022 files · +26 −10Browse files

Showing the changes to lib/random (1 of 2 files). Show all

Unified · Split

lib/random/random.go+11−3
@@ -10,10 +10,11 @@ import ( · 9 unmodified lines
10 "github.com/pkg/errors"10 "github.com/pkg/errors"
11)11)
12 12
13// String create a random string for test purposes.13// StringFn create a random string for test purposes using the random
14// number generator function passed in.
14//15//
15// Do not use these for passwords.16// Do not use these for passwords.
16func String(n int) string {17func StringFn(n int, randIntn func(n int) int) string {
17 const (18 const (
18 vowel = "aeiou"19 vowel = "aeiou"
19 consonant = "bcdfghjklmnpqrstvwxyz"20 consonant = "bcdfghjklmnpqrstvwxyz"
@@ -25,11 +26,18 @@ func String(n int) string { · 5 unmodified lines
25 for i := range out {26 for i := range out {
26 source := pattern[p]27 source := pattern[p]
27 p = (p + 1) % len(pattern)28 p = (p + 1) % len(pattern)
28 out[i] = source[mathrand.Intn(len(source))]29 out[i] = source[randIntn(len(source))]
29 }30 }
30 return string(out)31 return string(out)
31}32}
32 33
34// String create a random string for test purposes.
35//
36// Do not use these for passwords.
37func String(n int) string {
38 return StringFn(n, mathrand.Intn)
39}
40
33// Password creates a crypto strong password which is just about41// Password creates a crypto strong password which is just about
34// memorable. The password is composed of printable ASCII characters42// memorable. The password is composed of printable ASCII characters
35// from the base64 alphabet.43// from the base64 alphabet.