48 lines
954 B
Go
48 lines
954 B
Go
|
package adaptertest
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"io/fs"
|
||
|
|
||
|
"gitea.dwysokinski.me/twhelp/corev3/internal/adapter/internal/bunmodel"
|
||
|
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
|
||
|
"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),
|
||
|
)
|
||
|
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...))
|
||
|
}
|
||
|
|
||
|
func (f *Fixture) Server(tb TestingTB, id string) domain.Server {
|
||
|
tb.Helper()
|
||
|
|
||
|
row, err := f.f.Row("Server." + id)
|
||
|
require.NoError(tb, err)
|
||
|
|
||
|
s, ok := row.(*bunmodel.Server)
|
||
|
require.True(tb, ok)
|
||
|
|
||
|
converted, err := s.ToDomain()
|
||
|
require.NoError(tb, err)
|
||
|
|
||
|
return converted
|
||
|
}
|