gorm/tests/create.go

66 lines
1.3 KiB
Go
Raw Normal View History

2020-04-15 14:13:36 +03:00
package tests
import (
2020-05-23 11:08:50 +03:00
"strconv"
"time"
2020-04-15 14:13:36 +03:00
)
2020-05-23 11:08:50 +03:00
type Config struct {
Account bool
Pets int
Toys int
Company bool
Manager bool
Team int
Languages int
Friends int
2020-04-20 06:47:29 +03:00
}
2020-05-23 11:08:50 +03:00
func GetUser(name string, config Config) User {
var (
birthday = time.Now()
user = User{
Name: name,
2020-04-20 06:47:29 +03:00
Age: 18,
2020-05-23 11:08:50 +03:00
Birthday: &birthday,
2020-04-20 06:47:29 +03:00
}
2020-05-23 11:08:50 +03:00
)
2020-04-20 06:47:29 +03:00
2020-05-23 11:08:50 +03:00
if config.Account {
user.Account = Account{Number: name + "_account"}
2020-04-20 06:47:29 +03:00
}
2020-05-23 11:08:50 +03:00
for i := 0; i < config.Pets; i++ {
user.Pets = append(user.Pets, &Pet{Name: name + "_pet_" + strconv.Itoa(i+1)})
2020-04-20 06:47:29 +03:00
}
2020-05-23 11:08:50 +03:00
for i := 0; i < config.Toys; i++ {
user.Toys = append(user.Toys, Toy{Name: name + "_toy_" + strconv.Itoa(i+1)})
2020-04-20 18:35:18 +03:00
}
2020-05-23 11:08:50 +03:00
if config.Company {
user.Company = Company{Name: "company-" + name}
2020-04-20 18:35:18 +03:00
}
2020-05-23 11:08:50 +03:00
if config.Manager {
manager := GetUser(name+"_manager", Config{})
user.Manager = &manager
2020-04-20 18:35:18 +03:00
}
2020-05-23 11:08:50 +03:00
for i := 0; i < config.Team; i++ {
user.Team = append(user.Team, GetUser(name+"_team_"+strconv.Itoa(i+1), Config{}))
}
2020-05-14 10:05:04 +03:00
2020-05-23 11:08:50 +03:00
for i := 0; i < config.Languages; i++ {
name := "Locale_" + strconv.Itoa(i+0)
user.Languages = append(user.Languages, Language{Code: name, Name: name})
}
2020-05-14 10:05:04 +03:00
2020-05-23 11:08:50 +03:00
for i := 0; i < config.Friends; i++ {
f := GetUser(name+"_friend_"+strconv.Itoa(i+1), Config{})
user.Friends = append(user.Friends, &f)
}
2020-05-14 10:05:04 +03:00
2020-05-23 11:08:50 +03:00
return user
2020-04-20 06:47:29 +03:00
}