1
// Copyright 2013 Canonical Ltd. This software is licensed under the
2
// GNU Lesser General Public License version 3 (see the file COPYING).
4
// Factories for various types of objects that tests need to create.
13
// This should be refactored at some point, it does not belong in here.
14
// Perhaps we can add it to gocheck, or start a testtools-like project.
15
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz"
17
// MakeRandomString returns an arbitrary string of alphanumerical characters.
18
// TODO: This isn't really a random string, more of a random identifier.
19
func MakeRandomString(length int) string {
20
return string(MakeRandomByteSlice(length))
23
// MakeRandomString returns a slice of arbitrary bytes, all corresponding to
24
// alphanumerical characters in ASCII.
25
// TODO: This isn't really very random. Good tests need zero and "high" values.
26
func MakeRandomByteSlice(length int) []byte {
27
dest := make([]byte, length)
29
num := rand.Intn(len(chars))
30
rand_char := chars[num]
36
// MakeRandomBool returns an arbitrary bool value (true or false).
37
func MakeRandomBool() bool {
46
// Seed the pseudo-random number generator. Without this, each test run
47
// will get the same sequence of results from the math/rand package.
48
rand.Seed(int64(time.Now().Nanosecond()))