core/internal/domain/domaintest/version.go

34 lines
617 B
Go

package domaintest
import (
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/require"
)
type VersionConfig struct {
Code string
}
func (cfg *VersionConfig) init() {
if cfg.Code == "" {
cfg.Code = RandVersionCode()
}
}
func NewVersion(tb TestingTB, cfg VersionConfig) domain.Version {
cfg.init()
s, err := domain.UnmarshalVersionFromDatabase(
cfg.Code,
gofakeit.LetterN(10),
gofakeit.DomainName(),
gofakeit.TimeZoneRegion(),
)
require.NoError(tb, err)
return s
}
func RandVersionCode() string {
return gofakeit.LetterN(2)
}