Documentation
¶
Overview ¶
Package structmommy implement object generator for test purposes
Call Make to fill in your struct with random data. Use PostMake functions to define some of fields (Define), save struct to DB or whatever you please.
ToDo: Let generate multiple objects at once!
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Define ¶
func Define(keyValue ...interface{}) func(interface{}) error
Define is post Make function. Lets define values of struct fields
Example ¶
obj := struct { FieldA float32 FieldB uint8 }{} structmommy.SetSeed(26) structmommy.Make(&obj, structmommy.Define("FieldA", 2.0)) fmt.Println("FieldA:", obj.FieldA) fmt.Println("FieldB:", obj.FieldB)
Output: FieldA: 2 FieldB: 42
func Make ¶
Make fills in given object with radom data. Afterwords, if specified, PostMake functions are applied in order on the object. If any function will return no nil error, no other function is execute and error is returned
Example ¶
obj := struct { FieldA float32 FieldB uint8 }{} structmommy.SetSeed(26) structmommy.Make(&obj) fmt.Println("FieldA:", obj.FieldA) fmt.Println("FieldB:", obj.FieldB)
Output: FieldA: -1.5426473e+38 FieldB: 42
func PartialEqual ¶
func PartialEqual(obj interface{}, keyValue ...interface{}) (err error)
Checks values of subset of fields in a given struct. Accepts both object or it's refference.
Example (NotEqual) ¶
obj := struct { FieldA float32 FieldB uint8 }{ FieldA: 1.2, FieldB: 42, } err := structmommy.PartialEqual(obj, "FieldA", 123) if err != nil { fmt.Println("Error:", err) } else { fmt.Println("All fields as expected!") } fmt.Println("FieldA:", obj.FieldA) fmt.Println("FieldB:", obj.FieldB)
Output: Error: value of field 'FieldA' equals 1.2, expected 123 FieldA: 1.2 FieldB: 42
Example (Ok) ¶
obj := struct { FieldA float32 FieldB uint8 }{ FieldA: 1.2, FieldB: 42, } err := structmommy.PartialEqual(obj, "FieldA", 1.2, "FieldB", 42) if err != nil { fmt.Println("Error:", err) } else { fmt.Println("All fields as expected!") } fmt.Println("FieldA:", obj.FieldA) fmt.Println("FieldB:", obj.FieldB)
Output: All fields as expected! FieldA: 1.2 FieldB: 42
Types ¶
This section is empty.