Documentation ¶
Overview ¶
Package randomize has helpers for randomization of structs and fields
Index ¶
- func ByteSlice(nextInt func() int64, ln int) []byte
- func Date(nextInt func() int64) time.Time
- func EnumValue(nextInt func() int64, enum string) (string, error)
- func FormattedString(nextInt func() int64, fieldType string) (string, bool)
- func MediumInt(nextInt func() int64, fieldType string) (int32, bool)
- func StableDBName(input string) string
- func Str(nextInt func() int64, ln int) string
- func Struct(s *Seed, str interface{}, colTypes map[string]string, canBeNull bool, ...) error
- type Randomizer
- type Seed
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Date ¶
Date generates a random time.Time between 1850 and 2050. Only the Day/Month/Year columns are set so that Dates and DateTimes do not cause mismatches in the test data comparisons.
func EnumValue ¶
EnumValue takes an enum field type, parses it's definition to figure out valid values, and selects a random one from within them.
func FormattedString ¶
FormattedString checks a field type to see if it's in a range of special values and if so returns a randomized string for it.
func MediumInt ¶
MediumInt is a special case in mysql (thanks for that -_-) this function checks if the fieldtype matches and if so returns a random value in the proper range.
func StableDBName ¶
StableDBName takes a database name in, and generates a random string using the database name as the rand Seed. getDBNameHash is used to generate unique test database names.
Types ¶
type Randomizer ¶
type Randomizer interface { // Randomize should panic if there's no ability to randomize with the current parameters. // // nextInt can be called to create "random" sequential integers. This is done to avoid collisions in unique columns // for the tests. // // fieldType is used in the cases where the actual type (string, null string etc.) can actually be multiple // types of things that have specific randomization requirements, like a uuid for example is a normal null.String // but when randomizing that null string it must create a valid uuid or the database will reject it. // // shouldBeNull is a suggestion that a field should be null in this instance. The randomize implementation // can ignore this if the field cannot be null either because the type doesn't support it or there // is no ability for a field of this type to be null. Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) }
Randomizer allows a field to be randomized