summaryrefslogtreecommitdiff
path: root/pkg/testutils/testutils.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/testutils/testutils.go')
-rw-r--r--pkg/testutils/testutils.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/testutils/testutils.go b/pkg/testutils/testutils.go
index 4655e5844d..9c664ff253 100644
--- a/pkg/testutils/testutils.go
+++ b/pkg/testutils/testutils.go
@@ -1,10 +1,15 @@
package testutils
import (
+ "math/rand"
"testing"
"time"
)
+const chars = "abcdefghijklmnopqrstuvwxyz" +
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
+ "~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:` "
+
// Timeout calls f and waits for 100ms for it to complete.
// If it doesn't, it causes the tests to fail.
// t must be a valid testing context.
@@ -21,3 +26,12 @@ func Timeout(t *testing.T, f func()) {
case <-onDone:
}
}
+
+// RandomString returns random string of specified length
+func RandomString(length int) string {
+ res := make([]byte, length)
+ for i := 0; i < length; i++ {
+ res[i] = chars[rand.Intn(len(chars))]
+ }
+ return string(res)
+}