func defineFactories() { gory.Define("userRegistration", UserRegistrationView{}, func(factory gory.Factory) { factory["Email"] = gory.Sequence( func(n int) interface{} { return fmt.Sprintf("*****@*****.**", n) }) factory["Password"] = "******" }) gory.Define("userRegistrationDuplicate", UserRegistrationView{}, func(factory gory.Factory) { factory["Email"] = "*****@*****.**" factory["Password"] = "******" }) gory.Define("userRegistrationDupEmail", UserRegistrationView{}, func(factory gory.Factory) { factory["Email"] = gory.Sequence( func(n int) interface{} { return fmt.Sprintf("*****@*****.**") }) factory["Password"] = "******" }) gory.Define("userRegistrationMissingEmail", UserRegistrationView{}, func(factory gory.Factory) { factory["Password"] = "******" }) gory.Define("loginValid", LoginView{}, func(factory gory.Factory) { factory["Email"] = "*****@*****.**" factory["Password"] = "******" }) gory.Define("passwordChangeRequest", ChangePasswordView{}, func(factory gory.Factory) { factory["OldPassword"] = "******" factory["NewPassword"] = "******" }) gory.Define("passwordChangeRequestWrongPassword", ChangePasswordView{}, func(factory gory.Factory) { factory["OldPassword"] = "******" factory["NewPassword"] = "******" }) gory.Define("passwordChangeRequestMissingInfo", ChangePasswordView{}, func(factory gory.Factory) { factory["OldPassword"] = "******" }) }
/* Define two factories: one for a valid signature, and one for an invalid one (too young). */ func defineFactories() { gory.Define("signature", Signature{}, func(factory gory.Factory) { factory["FirstName"] = "Jane" factory["LastName"] = "Doe" factory["Age"] = 27 factory["Message"] = "I agree!" factory["Email"] = gory.Sequence( func(n int) interface{} { return fmt.Sprintf("*****@*****.**", n) }) }) gory.Define("signatureTooYoung", Signature{}, func(factory gory.Factory) { factory["FirstName"] = "Joey" factory["LastName"] = "Invalid" factory["Age"] = 10 factory["Email"] = "*****@*****.**" }) }
gory.Define("map", Map{}, func(factory gory.Factory) { strings := make(map[string]string, 0) strings["key"] = "value" factory["Strings"] = strings }) gory.Define("struct", Struct{}, func(factory gory.Factory) { factory["Bin"] = &Builtin{Int: 1} }) gory.Define("embedded", Embedded{}, func(factory gory.Factory) { factory["Int"] = 1 }) gory.Define("sequenced", Builtin{}, func(factory gory.Factory) { factory["Int"] = gory.Sequence(gory.IntSequencer) factory["String"] = gory.Sequence(func(n int) interface{} { return fmt.Sprintf("string %d", n) }) }) gory.Define("lazily", Lazily{}, func(factory gory.Factory) { factory["Uuid"] = gory.Lazy(func() interface{} { out, _ := exec.Command("uuidgen").Output() return string(out) }) }) }) func TestGory(t *testing.T) { RegisterFailHandler(Fail)