randomize

package
v3.0.0-rc2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2018 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package randomize has helpers for randomization of structs and fields

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteSlice

func ByteSlice(s *Seed, ln int) []byte

ByteSlice creates a random set of bytes (non-printables included)

func Date

func Date(s *Seed) time.Time

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

func EnumValue(s *Seed, enum string) (string, error)

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

func FormattedString(s *Seed, fieldType string) (string, bool)

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

func MediumInt(s *Seed, fieldType string) (int32, bool)

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

func StableDBName(input string) string

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.

func Str

func Str(s *Seed, ln int) string

Str creates a randomized string from printable characters in the alphabet

func Struct

func Struct(s *Seed, str interface{}, colTypes map[string]string, canBeNull bool, blacklist ...string) error

Struct gets its fields filled with random data based on the seed. It will ignore the fields in the blacklist. It will ignore fields that have the struct tag boil:"-"

Types

type Randomizer

type Randomizer interface {
	// Randomize should panic if there's no ability to randomize with the current parameters.
	// 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(s *Seed, fieldType string, shouldBeNull bool)
}

Randomizer allows a field to be randomized

type Seed

type Seed int64

Seed is an atomic counter for pseudo-randomization structs. Using full randomization leads to collisions in a domain where uniqueness is an important factor.

func NewSeed

func NewSeed() *Seed

NewSeed creates a new seed for pseudo-randomization.

func (*Seed) NextInt

func (s *Seed) NextInt() int

NextInt retrives an integer in order

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL