74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
package domaintest
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
|
|
"github.com/brianvoe/gofakeit/v6"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func RandTribeTag() string {
|
|
return gofakeit.LetterN(5)
|
|
}
|
|
|
|
type TribeConfig struct {
|
|
ID int
|
|
ServerKey string
|
|
Tag string
|
|
OD domain.OpponentsDefeated
|
|
BestRank int
|
|
BestRankAt time.Time
|
|
MostPoints int
|
|
MostPointsAt time.Time
|
|
MostVillages int
|
|
MostVillagesAt time.Time
|
|
}
|
|
|
|
func NewTribe(tb TestingTB, opts ...func(cfg *TribeConfig)) domain.Tribe {
|
|
tb.Helper()
|
|
|
|
cfg := &TribeConfig{
|
|
ID: RandID(),
|
|
ServerKey: RandServerKey(),
|
|
Tag: RandTribeTag(),
|
|
OD: NewOpponentsDefeated(tb),
|
|
BestRank: gofakeit.IntRange(1, 10000),
|
|
BestRankAt: time.Now(),
|
|
MostPoints: gofakeit.IntRange(1, 10000),
|
|
MostPointsAt: time.Now(),
|
|
MostVillages: gofakeit.IntRange(1, 10000),
|
|
MostVillagesAt: time.Now(),
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
|
|
t, err := domain.UnmarshalTribeFromDatabase(
|
|
cfg.ID,
|
|
cfg.ServerKey,
|
|
gofakeit.LetterN(50),
|
|
cfg.Tag,
|
|
gofakeit.IntRange(1, 10000),
|
|
gofakeit.IntRange(1, 10000),
|
|
gofakeit.IntRange(1, 10000),
|
|
gofakeit.IntRange(1, 10000),
|
|
gofakeit.IntRange(1, 10000),
|
|
cfg.OD,
|
|
gofakeit.URL(),
|
|
gofakeit.Float64Range(0.1, 99.9),
|
|
cfg.BestRank,
|
|
cfg.BestRankAt,
|
|
cfg.MostPoints,
|
|
cfg.MostPointsAt,
|
|
cfg.MostVillages,
|
|
cfg.MostVillagesAt,
|
|
time.Now(),
|
|
time.Time{},
|
|
)
|
|
require.NoError(tb, err)
|
|
|
|
return t
|
|
}
|