Documentation ¶
Overview ¶
Package factory is used for generating random values for testing purposes.
Index ¶
- func Bool() bool
- func BoolPtr() *bool
- func BoolSlice() []bool
- func Byte() byte
- func BytePtr() *byte
- func ByteSlice() []byte
- func Complex128() complex128
- func Complex128Ptr() *complex128
- func Complex128Slice() []complex128
- func Complex64() complex64
- func Complex64Ptr() *complex64
- func Complex64Slice() []complex64
- func Duration() time.Duration
- func DurationPtr() *time.Duration
- func DurationSlice() []time.Duration
- func Email() string
- func Float32() float32
- func Float32Ptr() *float32
- func Float32Slice() []float32
- func Float64() float64
- func Float64Ptr() *float64
- func Float64Slice() []float64
- func Int() int
- func Int16() int16
- func Int16Ptr() *int16
- func Int16Slice() []int16
- func Int32() int32
- func Int32Ptr() *int32
- func Int32Slice() []int32
- func Int64() int64
- func Int64Ptr() *int64
- func Int64Slice() []int64
- func Int8() int8
- func Int8Ptr() *int8
- func Int8Slice() []int8
- func IntPtr() *int
- func IntSlice() []int
- func Name() string
- func Populate(s interface{}, skipUnsupported bool) error
- func Rune() rune
- func RunePtr() *rune
- func RuneSlice() []rune
- func String() string
- func StringPtr() *string
- func StringSlice() []string
- func Time() time.Time
- func TimeAfter(t time.Time) time.Time
- func TimeBefore(t time.Time) time.Time
- func URL() url.URL
- func Uint() uint
- func Uint16() uint16
- func Uint16Ptr() *uint16
- func Uint16Slice() []uint16
- func Uint32() uint32
- func Uint32Ptr() *uint32
- func Uint32Slice() []uint32
- func Uint64() uint64
- func Uint64Ptr() *uint64
- func Uint64Slice() []uint64
- func Uint8() uint8
- func Uint8Ptr() *uint8
- func Uint8Slice() []uint8
- func UintPtr() *uint
- func UintSlice() []uint
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolPtr ¶
func BoolPtr() *bool
BoolPtr generates a random bool value and returns the pointer to it.
func BytePtr ¶
func BytePtr() *byte
BytePtr generates a random byte value and returns the pointer to it.
func Complex128Ptr ¶
func Complex128Ptr() *complex128
Complex128Ptr generates a random complex128 value and returns the pointer to it.
func Complex128Slice ¶
func Complex128Slice() []complex128
Complex128Slice generates a random complex128 slice.
func Complex64Ptr ¶
func Complex64Ptr() *complex64
Complex64Ptr generates a random complex64 value and returns the pointer to it.
func Complex64Slice ¶
func Complex64Slice() []complex64
Complex64Slice generates a random complex64 slice.
func DurationPtr ¶
DurationPtr generates a random time.Duration value and returns the pointer to it.
func DurationSlice ¶
DurationSlice generates a random time.Duration slice.
func Email ¶
func Email() string
Email generates a random email address.
Example ¶
package main import ( "fmt" "github.com/gardenbed/basil/factory" ) func main() { email := factory.Email() fmt.Printf("%s\n", email) }
Output:
func Float32Ptr ¶
func Float32Ptr() *float32
Float32Ptr generates a random float32 value and returns the pointer to it.
func Float64Ptr ¶
func Float64Ptr() *float64
Float64Ptr generates a random float64 value and returns the pointer to it.
func Int16Ptr ¶
func Int16Ptr() *int16
Int16Ptr generates a random int16 value and returns the pointer to it.
func Int32Ptr ¶
func Int32Ptr() *int32
Int32Ptr generates a random int32 value and returns the pointer to it.
func Int64Ptr ¶
func Int64Ptr() *int64
Int64Ptr generates a random int64 value and returns the pointer to it.
func Int8Ptr ¶
func Int8Ptr() *int8
Int8Ptr generates a random int8 value and returns the pointer to it.
func Name ¶
func Name() string
Name generates a random human name.
Example ¶
package main import ( "fmt" "github.com/gardenbed/basil/factory" ) func main() { name := factory.Name() fmt.Printf("%s\n", name) }
Output:
func Populate ¶
Populate receives the pointer to a struct and populates all fields, including the nested fields, with random values. If skipUnsupported set to false, an error will be returned in case a type is not supported.
Example ¶
package main import ( "fmt" "log" "net/url" "time" "github.com/gardenbed/basil/factory" ) func main() { object := struct { String string Bool bool Int int Uint uint Float64 float64 Complex128 complex128 Nested struct { Duration time.Duration Time *time.Time URL *url.URL } }{} if err := factory.Populate(&object, false); err != nil { log.Fatalf("populate error: %s", err) } fmt.Printf("%+v\n", object) }
Output:
func RunePtr ¶
func RunePtr() *rune
RunePtr generates a random rune value and returns the pointer to it.
func String ¶
func String() string
String generates a random string value.
Example ¶
package main import ( "fmt" "github.com/gardenbed/basil/factory" ) func main() { s := factory.String() fmt.Printf("%s\n", s) }
Output:
func StringPtr ¶
func StringPtr() *string
StringPtr generates a random string value and returns the pointer to it.
Example ¶
package main import ( "fmt" "github.com/gardenbed/basil/factory" ) func main() { s := factory.StringPtr() fmt.Printf("%s\n", *s) }
Output:
func StringSlice ¶
func StringSlice() []string
StringSlice generates a random string slice.
Example ¶
package main import ( "fmt" "github.com/gardenbed/basil/factory" ) func main() { s := factory.StringSlice() fmt.Printf("%s\n", s) }
Output:
func Time ¶
Time generates a random time.Time value.
Example ¶
package main import ( "fmt" "github.com/gardenbed/basil/factory" ) func main() { t := factory.Time() fmt.Printf("%s\n", t) }
Output:
func TimeAfter ¶
TimeAfter generates a random time.Time value after a given time.
Example ¶
package main import ( "fmt" "time" "github.com/gardenbed/basil/factory" ) func main() { t := factory.TimeAfter(time.Now()) fmt.Printf("%s\n", t) }
Output:
func TimeBefore ¶
TimeBefore generates a random time.Time value before a given time.
Example ¶
package main import ( "fmt" "time" "github.com/gardenbed/basil/factory" ) func main() { t := factory.TimeBefore(time.Now()) fmt.Printf("%s\n", t) }
Output:
func URL ¶
URL generates a random url.URL value.
Example ¶
package main import ( "fmt" "github.com/gardenbed/basil/factory" ) func main() { u := factory.URL() fmt.Printf("%s\n", &u) }
Output:
func Uint16Ptr ¶
func Uint16Ptr() *uint16
Uint16Ptr generates a random uint16 value and returns the pointer to it.
func Uint32Ptr ¶
func Uint32Ptr() *uint32
Uint32Ptr generates a random uint32 value and returns the pointer to it.
func Uint64Ptr ¶
func Uint64Ptr() *uint64
Uint64Ptr generates a random uint64 value and returns the pointer to it.
func Uint8Ptr ¶
func Uint8Ptr() *uint8
Uint8Ptr generates a random uint8 value and returns the pointer to it.
Types ¶
This section is empty.