package domaintest import ( "net/url" "time" "gitea.dwysokinski.me/twhelp/corev3/internal/domain" "github.com/brianvoe/gofakeit/v7" "github.com/stretchr/testify/require" ) func RandServerKey() string { return gofakeit.LetterN(5) } type ServerCursorConfig struct { Key string Open bool } func NewServerCursor(tb TestingTB, opts ...func(cfg *ServerCursorConfig)) domain.ServerCursor { tb.Helper() cfg := &ServerCursorConfig{ Key: RandServerKey(), Open: gofakeit.Bool(), } for _, opt := range opts { opt(cfg) } sc, err := domain.NewServerCursor(cfg.Key, cfg.Open) require.NoError(tb, err) return sc } type ServerConfig struct { Key string VersionCode string URL *url.URL Open bool Special bool PlayerDataSyncedAt time.Time PlayerSnapshotsCreatedAt time.Time TribeDataSyncedAt time.Time TribeSnapshotsCreatedAt time.Time VillageDataSyncedAt time.Time EnnoblementDataSyncedAt time.Time } func NewServer(tb TestingTB, opts ...func(cfg *ServerConfig)) domain.Server { tb.Helper() cfg := &ServerConfig{ Key: RandServerKey(), VersionCode: RandVersionCode(), Open: true, Special: false, PlayerDataSyncedAt: time.Time{}, PlayerSnapshotsCreatedAt: time.Time{}, TribeDataSyncedAt: time.Time{}, TribeSnapshotsCreatedAt: time.Time{}, VillageDataSyncedAt: time.Time{}, EnnoblementDataSyncedAt: time.Time{}, } for _, opt := range opts { opt(cfg) } if cfg.URL == nil { cfg.URL = &url.URL{ Scheme: "https", Host: cfg.Key + "." + gofakeit.DomainName(), } } s, err := domain.UnmarshalServerFromDatabase( cfg.Key, cfg.VersionCode, cfg.URL.String(), cfg.Open, cfg.Special, 0, 0, 0, 0, 0, 0, NewServerConfig(tb), NewBuildingInfo(tb), NewUnitInfo(tb), time.Now(), cfg.PlayerDataSyncedAt, cfg.PlayerSnapshotsCreatedAt, cfg.TribeDataSyncedAt, cfg.TribeSnapshotsCreatedAt, cfg.VillageDataSyncedAt, cfg.EnnoblementDataSyncedAt, ) require.NoError(tb, err) return s }