craban/services/store/testlib.go

41 lines
719 B
Go
Raw Normal View History

2021-09-11 22:50:53 +01:00
package store
import (
"testing"
"git.ctrlz.es/mgdelacroix/rmsn/model"
"github.com/icrowley/fake"
"github.com/stretchr/testify/require"
)
type TestHelper struct {
t *testing.T
store *Store
}
func NewTestHelper(t *testing.T) (*TestHelper, func()) {
s, err := NewStore(":memory:")
require.NoError(t, err)
teardown := func() {
require.NoError(t, s.Close())
}
return &TestHelper{t: t, store: s}, teardown
}
func (th *TestHelper) NewUser() *model.User {
user := &model.User{
Name: fake.FullName(),
Mail: fake.EmailAddress(),
Username: fake.UserName(),
Password: fake.SimplePassword(),
}
newUser, err := th.store.User().Create(user)
require.NoError(th.t, err)
return newUser
}