core/internal/bun/buntest/fixture.go
Dawid Wysokiński 08a7f0c504
Some checks failed
ci/woodpecker/push/govulncheck Pipeline failed
ci/woodpecker/push/test Pipeline failed
feat: server snapshots (#49)
Reviewed-on: #49
2024-05-09 07:49:04 +00:00

40 lines
850 B
Go

package buntest
import (
"context"
"io/fs"
"gitea.dwysokinski.me/twhelp/core/internal/bun/bunmodel"
"github.com/stretchr/testify/require"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dbfixture"
)
type Fixture struct {
f *dbfixture.Fixture
}
func NewFixture(bunDB *bun.DB) *Fixture {
bunDB.RegisterModel(
(*bunmodel.Version)(nil),
(*bunmodel.Server)(nil),
(*bunmodel.Tribe)(nil),
(*bunmodel.Player)(nil),
(*bunmodel.Village)(nil),
(*bunmodel.Ennoblement)(nil),
(*bunmodel.TribeChange)(nil),
(*bunmodel.ServerSnapshot)(nil),
(*bunmodel.TribeSnapshot)(nil),
(*bunmodel.PlayerSnapshot)(nil),
)
return &Fixture{
f: dbfixture.New(bunDB),
}
}
//nolint:revive
func (f *Fixture) Load(tb TestingTB, ctx context.Context, fsys fs.FS, names ...string) {
tb.Helper()
require.NoError(tb, f.f.Load(ctx, fsys, names...))
}