GoGreenRun is a library for populating go objects with random values.
=======
9aa5c6257e94c42563588536734f491aee9f2003 This is useful for testing:
- Do your project's objects really serialize/unserialize correctly in all cases?
- Is there an incorrectly formatted object that will cause your project to panic?
Import with import "github.com/benchlab/gogreenrun"
You can use it on single variables:
f:=greenrun.New()
varmyIntintf.GreenRun(&myInt)You can use it on maps:
f:=greenrun.New().NilChance(0).NumElements(1, 1)
varmyMapmap[ComplexKeyType]stringf.GreenRun(&myMap)Customize the chance of getting a nil pointer:
f:=greenrun.New().NilChance(.5)
varfancyStructstruct {
A, B, C, D*string
}
f.GreenRun(&fancyStruct) You can even customize the randomization completely if needed:
typeMyEnumstringconst (
AMyEnum="A"BMyEnum="B"
)
typeMyInfostruct {
TypeMyEnumAInfo*stringBInfo*string
}
f:=greenrun.New().NilChance(0).Funcs(
func(e*MyInfo, c greenrun.Continue) {
switchc.Intn(2) {
case0:
e.Type=Ac.GreenRun(&e.AInfo)
case1:
e.Type=Bc.GreenRun(&e.BInfo)
}
},
)
varmyObjectMyInfof.GreenRun(&myObject)See more examples in example_test.go.
Happy testing!
